我正在尝试使用动态tabsetPanel,其中tabPanel的数量根据selectInput而变化。 tabset按预期显示,但tabPanel内容仅显示在活动选项卡上。这是代码:
library(shiny)
ui <- fluidPage (
selectInput("tabset", "Choose a Tabset to view:",
choices = c("Tabset One" = "one",
"Tabset Two" = "two",
"Tabset Three" = "three")
),
uiOutput("ui")
)#end of ui
cont <- c("TextOne", "TextTwo", "TextThree")
one <- function() {
tp1 <- tabPanel("TabsetOne_TabOne", lapply(paste(cont), textOutput))
ts <- tabsetPanel(type="tabs", tp1)
return(ts)
}#end of TabsetOne
two <- function() {
tp1 <- tabPanel("TabsetTwo_TabOne", lapply(paste(cont), textOutput))
tp2 <- tabPanel("TabsetTwo_TabTwo", lapply(paste(cont), textOutput))
ts <- tabsetPanel(type="tabs", tp1, tp2)
return(ts)
}#end of TabsetOne
three <- function() {
tp1 <- tabPanel("TabsetThree_TabOne", lapply(paste(cont), textOutput))
tp2 <- tabPanel("TabsetThree_TabTwo", lapply(paste(cont), textOutput))
tp3 <- tabPanel("TabsetThree_TabThree", lapply(paste(cont), textOutput))
ts <- tabsetPanel(type="tabs", tp1, tp2, tp3)
return(ts)
}#end of TabsetOne
server <- function(input, output) {
ds <- reactive({
switch(input$tabset,
"one" = one(),
"two" = two(),
"three" = three()
)#end of switch
})#end of reactive
output$ui <- renderUI({
ds()
})#end of renderUI
output$TextOne <- renderText({
paste("Text Output One")
})#end of TextOne
output$TextTwo <- renderText({
paste("Text Output Two")
})#end of TextTwo
output$TextThree <- renderText({
paste("Text Output Three")
})#end of TextThree
}#end of server
runApp(list(ui=ui, server=server))