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

[亡魂溺海] 提交于 2020-01-25 09:41:05

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/50629365/how-to-acheive-conditional-output-based-on-tab-selection-in-shiny-app

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!