【发布时间】:2017-07-21 06:22:12
【问题描述】:
我正在尝试使用 lapply 在 Shiny 中的 tabsetPanel 中创建多个选项卡,基于以下示例:http://shiny.rstudio.com/gallery/creating-a-ui-from-a-loop.html。下面是我的app.R 代码。当我运行它时,它不会创建 5 个选项卡,也不会打印每个选项卡的名称。我究竟做错了什么?
library(shiny)
ui <- pageWithSidebar(
headerPanel("xxx"),
sidebarPanel(),
mainPanel(
tabsetPanel(id='t',
lapply(1:5, function(i) {
tabPanel(
title=paste0('tab', i),
textOutput(paste0('a',i))
)
})
)
)
)
server <- function(input, output) {
observe({
print(input$t)
})
lapply(1:5, function(j) {
output[[paste0('a',j)]] <- renderPrint({
input$t
})
})
}
shinyApp(ui, server)
【问题讨论】: