簡體   English   中英

動態的地塊數量

[英]Dynamic number of plots in Shiny

我想根據用戶可以從中選擇的一些數據行在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)

現在發布的代碼中的問題是y變量未定義L

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

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

y $ aq1不存在。 因此,現在您的繪圖語句plot(x,y)與plot(x)相同。 (在定義y的語句后嘗試print(y)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM