以下作品
library(shiny)
ui <- (basicPage(
tabsetPanel(id = "tabs",
tabPanel("Tab A", value = "A",
"This is Tab A content",
textOutput("tabA")),
tabPanel("Tab B", value = "B",
"Here's some content for tab B.",
textOutput("tabB")))
))
server <- function(input, output, session) {
output$tabA <- renderText({paste0("You are viewing tab ", input$tabs)})
output$tabB <- renderText({paste0("You are viewing tab ", input$tabs)})
}
shinyApp(ui = ui, server = server)
我想根据选择的选项卡选择输出的名称。
output[["tabA"]] <- renderText({paste0("You are viewing tab ", input$tabs)})
以上情况很好但下面的内容确实无效,因为它需要反应性上下文。
output[[paste0("tab", input$tabs)]] <- renderText({paste0("You are viewing tab ", input$tabs)})
有办法做到这一点吗?
答案 0 :(得分:1)
这样的东西?
library(shiny)
ui <- (basicPage(
tabsetPanel(id = "tabs",
tabPanel("Tab A", value = "A","This is Tab A content",textOutput("tabA")),
tabPanel("Tab B", value = "B","Here's some content for tab B.",textOutput("tabB")))
))
server <- function(input, output, session) {
observe({
output[[paste0("tab", input$tabs)]] <- renderText({paste0("You are viewing tab ", input$tabs)})
})
}
shinyApp(ui = ui, server = server)