user2814482
user2814482

Reputation: 651

how to achieve conditional output based on tab selection in shiny app

I would like to have 2 tabs in the sidebar "otu selection" and "anova". Based on the tab that is selected in the sidebar I would like to output different plots or tables in the main panel.

At the moment I am getting an error:

ERROR: object 'input.tabs' not found

Here is my script.

ui <- fluidPage(
  # Make a title to display in the app
  titlePanel(" Exploring the Effect of Metarhizium on the Soil and Root Microbiome "),
  # Make the Sidebar layout
  sidebarLayout(
    # Put in the sidebar all the input functions
    sidebarPanel(
      tabsetPanel(id="tabs",
        tabPanel("otu","OTU selection", selectInput('dataset', 'dataset', names(abundance_tables)),
                 uiOutput("otu"), br(),
                 # Add comment
                 p("For details on OTU identification please refer to the original publications")),
        tabPanel("anova","anova", sliderInput('pval','p-value for significance',
                                      value=5,min=0,max=0.5,step=0.00001),
                 selectInput('fact_ofInt','factor of interest',FactorsOfInt))
        )
    ),
    # Put in the main panel of the layout the output functions 
    mainPanel(
      conditionalPanel(condition=input.tabs == 'otu',
        plotOutput('plot')
     #   dataTableOutput("table")
      ),
     conditionalPanel(condition=input.tabs == 'anova',
                      plotOutput('plot2')
                      #   dataTableOutput("table")
     )
    )
  )
)

I have looked at similar posts, but still need some guidance.

Thanks

Upvotes: 1

Views: 1802

Answers (1)

Sovik Gupta
Sovik Gupta

Reputation: 157

your conditional panel condition is declared in a wrong format. The right format is

 # Put in the main panel of the layout the output functions 
    mainPanel(
      conditionalPanel(condition="input.tabs == 'otu'",
        plotOutput('plot')
     #   dataTableOutput("table")
      ),
     conditionalPanel(condition="input.tabs == 'anova'",
                      plotOutput('plot2')
                      #   dataTableOutput("table")
     )
    )

So conditional is always assigned with in "", and with in the "" the equality check is performed.

Upvotes: 3

Related Questions