简体   繁体   English

动态的地块数量

[英]Dynamic number of plots in Shiny

I want to display a dynamic number of plots in Shiny according to some data rows that the user can pick from. 我想根据用户可以从中选择的一些数据行在Shiny中显示动态的绘图数量。 I achieved this, however I keep getting the same plot. 我做到了这一点,但是我不断得到同样的情节。 The right amount of times, but always with the wrong data. 正确的时间量,但总是带有错误的数据。 I already tried debugging, but the loops seem to work. 我已经尝试过调试,但是循环似乎可以正常工作。 Three plots with the plot id's 'plot1' 'plot2' 'plot3' are created. 创建了三个具有图ID为'plot1''plot2''plot3'的图。 I also checked the browser inside the loop where I create the plots...the x and y values are the right ones... Anyone have a clue what I'm doing wrong? 我还在创建图表的循环中检查了浏览器... 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)

The issue in your code as it is posted right now, is that the y variable is not definedL 现在发布的代码中的问题是y变量未定义L

  x <- alphacat[,paramnames[i]]
  y <- alphacat$aq1

  output[[plotname]] <- renderPlot({
    plot(x,y)
  })

y$aq1 does not exist. y $ aq1不存在。 Therefore, right now your plotting statement plot(x,y) is the same as plot(x). 因此,现在您的绘图语句plot(x,y)与plot(x)相同。 (try print(y) after the statement where you define y) (在定义y的语句后尝试print(y)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM