【发布时间】:2020-10-09 08:29:50
【问题描述】:
我正在尝试使用循环生成的绘图填充动态生成的选项卡,但无法让选项卡填充循环中生成的所有绘图。
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_content() 索引中的最后一个图填充两个选项卡。我不知道如何从plot_content() 获取所有绘图以动态填充创建的适当数量的选项卡。
【问题讨论】: