Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 使用循环中的动态打印渲染动态选项卡_R_Dynamic_Shiny_Reactive - Fatal编程技术网

R 使用循环中的动态打印渲染动态选项卡

R 使用循环中的动态打印渲染动态选项卡,r,dynamic,shiny,reactive,R,Dynamic,Shiny,Reactive,我试图用循环生成的绘图填充动态生成的选项卡,但无法用循环中生成的所有绘图填充选项卡 shinyUI(pageWithSidebar( headerPanel("Dynamic number of plots"), sidebarPanel( ), mainPanel( # This is the dynamic UI for the plots uiOutput("IndividualPlots") ) )) server <- function(input, output)

我试图用循环生成的绘图填充动态生成的选项卡,但无法用循环中生成的所有绘图填充选项卡

shinyUI(pageWithSidebar(

  headerPanel("Dynamic number of plots"),

sidebarPanel(
),

mainPanel(
# This is the dynamic UI for the plots
uiOutput("IndividualPlots")
 )
))

server <- function(input, output) {

output$IndividualPlots <- renderUI({
  if (is.null(input$data_cqt0)) {
    return()
  }
  plot_content()
  shiny:::buildTabset(
    id = "t",
    lapply(1:PageNumber(), function(i){
      plotname <- paste("plot", i, sep="")
      tabPanel(title = sprintf("Page_%s",i),
               #browser(),
               plotOutput(plotname,width = "800px", height = "600px") 
      )
    }), 
    paste0("nav nav-","tabs")) %>% (function(x){
      tags$div(class = "tabbable", x[[1]], x[[2]])
    })
})


plot_content<- reactive({
  for (i in 1:PageNumber()) {
    local({
      my_i <- i
      plotname <- paste("plot", my_i, sep="")   
      output[[plotname]] <- renderPlot({
          print(Plots()[[i]])
      })
    })
  }
})

PageNumber <- reactive({
  data <- data()
  return(PlotPageNumber(data, input$Class)) ## Returns number of plots
})



Plots <- reactive({
    data <- data()
     return(PlotFunction(data, input$Class)) ## Returns plots in list
    })
   }

这段代码几乎可以工作,但它用plot_内容索引中的最后一个plot填充了两个选项卡。我一直想知道如何从plot_内容中获取所有绘图,以动态填充创建的适当数量的选项卡

你的问题是,有光泽的反动派评价懒惰。因此,当打印渲染时,索引i的值等于所有打印的页码。我对此问题的首选解决方案是创建一个模块来管理绘图的显示。该模块还可以处理任何其他与绘图相关的活动。模块的不同实例管理每个单独的绘图。结果是代码通常比其他解决方案更短、更健壮、更易于理解和维护

虽然OP的主要问题与你的不同,但我的回答(特别是第二次修订版)就是对这项技术的演示