我正在进行一项使用Shiny开发交互式仪表板的任务,但是我设法做到了,但是当我合并代码以显示3个地块时,其中有2个出现了,但是第3个却给了我一个错误:
[:下标超出范围[没有可用的堆栈跟踪]
这是我的代码
library(shiny)
ui=fluidPage(
# Give the page a title
titlePanel("Age ranges according to program"),
# Generate a row with a sidebar
sidebarLayout(
# Define the sidebar with one input
sidebarPanel(
actionButton(inputId = "MBA", label = "MBA"),
actionButton(inputId = "MSLOD", label = "MSLOD"),
actionButton(inputId = "MSQBE", label = "MSQBE"),
selectInput("Program", "Program:", choices=colnames(Majoraccordingtogender)),
selectInput("Program", "Position:", choices=colnames(Majorsaccordingtoposition))
),
# Create a spot for the barplot
mainPanel(
fluidRow(
column(6,plotOutput("hist")),
column(8,plotOutput("Plot")),
column(10,plotOutput("Plot1"))
)
)
)
)
server <- function(input, output) {
rv <- reactiveValues(data = Majorsaccordingtoage[1,1:4])
observeEvent(input$MBA, { rv$data <- Majorsaccordingtoage[1,1:4] })
observeEvent(input$MSLOD, { rv$data <- Majorsaccordingtoage[2,1:4] })
observeEvent(input$MSQBE, { rv$data <- Majorsaccordingtoage[3,1:4] })
output$hist <- renderPlot({
barplot(rv$data,
main=input$radio,
ylab="Number employees",
xlab="Ages Range",col=rainbow(4))
})
output$Plot <- renderPlot({
pct <- round(as.numeric(Majoraccordingtogender[,input$Program])/sum(as.numeric(Majoraccordingtogender[,input$Program]))*100)
lbls <- paste(pct)
lbls <- paste(lbls,"%",sep="")
pie(Majoraccordingtogender[,input$Program],
main=input$Program,
col=rainbow(2),
labels = lbls)
legend("topright", c("Male", "Female"), cex=0.8,fill=rainbow(length(Majoraccordingtogender[,input$Program])))
})
output$Plot1 <- renderPlot({
barplot(Majorsaccordingtoposition[,input$Program],
main=input$Program,col=rainbow(3),xlab = "Programs"
)
})
}
shinyApp(ui = ui, server = server)
我的数据集如下
主要收费标准
0-25 25-30 30-40 40-65
MBA 5 133 258 106
MSLOD 4 59 60 28
MSQBE 2 34 64 28
主要根据位置
DIRECTOR MANAGER OFFICER NOT EMPLOYEE NOT MENTIONED
MBA 10 67 172 104 10
MSLOD 1 17 57 22 6
MSQBE 0 15 39 13 3
主要性别
MBA MSLOD MSQBE
Male 281 79 44
Female 221 72 84
请注意所有数据类型都是矩阵。
感谢您的帮助
答案 0 :(得分:0)
只是放错了逗号。
Majorsaccordingtoposition[,input$Program]
至Majorsaccordingtoposition[input$Program,]
output$Plot1 <- renderPlot({
barplot(Majorsaccordingtoposition[input$Program,],
main=input$Program,col=rainbow(3),xlab = "Programs"
)
})
答案 1 :(得分:0)
感谢您的帮助,我找到了答案
(button Click)
float one = geting_id_one.getText().toString();
float two = geting_id_two.getText().toString();
if (one>two){
Toast.makeText(MainActivity.this,"TextView1 Bigger than TextView2", Toast.LENGTH_SHORT).show();
}
if (one>two){
Toast.makeText(MainActivity.this,"TextView2 Bigger than TextView1", Toast.LENGTH_SHORT).show();
}
in main = inpu $ program是问题,因此我不得不更改世界中的“ program” ui和服务器使用其他任何文字
output$Plot1 <- renderPlot({
barplot(Majorsaccordingtoposition[,input$Program],
main=input$Program,col=rainbow(3),xlab = "Programs"
)
})
因为它类似于下面的代码
selectInput("Program", "Position:", choices=colnames(Majorsaccordingtoposition))