我希望根据用户可以选择的一些数据行在Shiny中显示动态数量的图。我实现了这个目标,但是我仍然得到同样的情节。适量的次数,但总是错误的数据。 我已经尝试过调试,但循环似乎有效。创建了具有情节id'plot1''plot2''plot3'的三个图。我还检查了循环中的浏览器,我创建了图... x和y值是正确的... 任何人都知道我做错了什么?
ui <- bootstrapPage(
navbarPage("Anpassung Lastmodell",
tabPanel("Graph",
fluidRow(width=4,
uiOutput('alphaui'),
uiOutput('graphui')
)
)
)
)
server <- function(input, output, session) {
## Output Graphs
output$alphaui <- renderUI({
# Here I usually have a manually uploaded dataset, so that's why this part is in a dynamic UI
# The user selects the columns of the data he wants in the plots
alphacat <- beaver1
paramnames <- colnames(alphacat)
graphparam <- vector("list",length(paramnames))
for (i in 1:length(paramnames)) {
graphparam[[i]] <- list(checkboxInput(paste0("graphparam",i,sep=""),paramnames[i],value=FALSE))
}
graphparam[[i+1]] <- actionButton("graph_button", "Los!",width="200px")
return(graphparam)
})
output$graphui <- renderUI({
graph <- plots()
graph
})
plots <- eventReactive(input$graph_button, {
# Selecting data to be plotted
alphacat <- beaver1
paramnames <- colnames(alphacat)
paramnames_keep <- isolate(unlist(reactiveValuesToList(input)[paste0("graphparam",1:length(paramnames),sep="")]))
paramnames <- cbind(paramnames,paramnames_keep)
paramnames <- subset(paramnames,paramnames[,"paramnames_keep"]==TRUE,"paramnames")
graph <- list()
i <- 1
for (i in 1:length(paramnames)) {
plotname <- paste("plot",i, sep="")
x <- alphacat[,paramnames[i]]
y <- alphacat$time
output[[plotname]] <- renderPlot({
plot(x,y)
})
graph[[i]] <- plotOutput(plotname,height=330,width=300)
tagList(graph)
}
return(graph)
})
}
shinyApp(ui,server)
答案 0 :(得分:0)
现在发布的代码中的问题是y变量未定义为L
x <- alphacat[,paramnames[i]]
y <- alphacat$aq1
output[[plotname]] <- renderPlot({
plot(x,y)
})
y $ aq1不存在。因此,现在您的绘图语句图(x,y)与plot(x)相同。 (在您定义y)
的语句后尝试print(y)