Home:ALL Converter>How to use input$tabs to reference the output name in a Shiny app

How to use input$tabs to reference the output name in a Shiny app

Ask Time:2018-03-07T00:22:29         Author:Oh No

Json Formatter

the below works

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)

I would like to select the name of the output depending on which tab is selected.

output[["tabA"]] <- renderText({paste0("You are viewing tab ", input$tabs)})

the above is fine but the below does't work since it wants a reactive context.

 output[[paste0("tab", input$tabs)]] <- renderText({paste0("You are viewing tab ", input$tabs)})

Is there a way to do this?

Author:Oh No,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/49135528/how-to-use-inputtabs-to-reference-the-output-name-in-a-shiny-app
yy