我试图在tabsetPanel参数中创建动态数量的数据表。感谢各种不同的帖子,我来到这个“不工作的解决方案”。
表格被正确渲染和加入,但tabsetPanel无法创建,我想知道如何使这项工作,任何帮助表示赞赏:
library(DT)
# for simplification this is not dynamic but created without hardcoded variable calls.
portalData <- lapply(1:10,function(x)data.frame(rnorm(5,1))
names(portalData) <- 1:10
shinyApp(
ui = pageWithSidebar(
headerPanel("Dynamic number of tables inside tabpanels"),
sidebarPanel(
),
mainPanel(
uiOutput("tables")
)
),
server = function(input, output) {
observe({
output$tables <- renderUI({
names_list <- lapply(seq_along(portalData), function(i){
tablename <- paste(names(portalData)[i])
tabPanel(dataTableOutput(tablename))
})
do.call(tabsetPanel,do.call(tagList, names_list))
})
for(i in 1:length(portalData)){
local({
i2 <- i
output[[names(portalData)[i2]]] <- renderDataTable({portalData[[i2]]})
})
}
})
})