Shiny module for selecting graph runs into problem when displaying those graphs elsewhere.

I was looking at an example app in stackoverflow and noticed something odd.

This app lets you select a which graph you want to see from a list of options.
I added tabs to the code from stackoverflow, seen below, for the main selection and each of the graphs that are made.

I noticed that as I added graphs to the tab they would no longer appear in the selection.
E.G. when I added the table the selected tab would no longer show a table if table was selected.

Does anyone know why this is and how to avoid this? It currently looks like it's somehow stealing the name from the selected graph to display as normal. I mostly just want to know since it probably has to do with namespaces and an answer to this will help me understand the topic a bit better.

module_ui <- function(id){
  ns <- NS(id)
                label = "Select type of output", 
                selected = "table",
                choices = c("table", "barplot", "graph") 
      ## tabPanel("table", tableOutput(ns("table"))),
      ## tabPanel("graph", plotOutput(ns("scatterplot"))),
      tabPanel("barplot", plotOutput(ns("barplot")))

module_server <- function(input, output, session){
  ns <- session$ns
  output$table <- renderTable({head(women)}) 
  output$barplot <- renderPlot({barplot(women$height)})
  output$scatterplot <- renderPlot({plot(women$height ~ women$weight)})
  output_selected <- reactive({input$output_type})
  output$diff_outputs <- renderUI({
    if (is.null(output_selected()))
      "table" = tableOutput(ns("table")),
      "barplot" = plotOutput(ns("barplot")),
      "graph" = plotOutput(ns("scatterplot"))

ui <- fluidPage(
  titlePanel("Dynamically generated user interface components"),

server <- function(input, output){
  callModule(module_server, "module")

shinyApp(ui = ui, server = server)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.