title: How to reactively show and hide an object in a sidebar panel?
body: <p>I am trying to conditionally (reactively) render a <code>selectInput()</code> box in the sidebar panel in an App. Below is excerpted reproducible code.</p>
  <p>Basically, if the user opts to view &quot;Strats&quot;, then the <code>selectInput()</code> box should appear in the sidebar panel. Otherwise, the <code>selectInput()</code> box should remain hidden. Default condition should be hidden until &quot;Strats&quot; is selected.</p>
  <p>In the fuller App this excerpt derives from, there are 6 items to conditionally render in the sidebarpanel, not just one.</p>
  <p>My attempts to show/hide the <code>selectInput()</code> box are commented as # ATTEMPT in the below reproducible code. The longish <code>renderTable()</code> function below can be safely ignored: I chose not reduce it as much as I could have to make this more MWE, since it is ignorable and will make any solution easier to stitch back into the fuller App.</p>
  <p>The images at the bottom better explain what I am trying to do.</p>
  <p>Reproducible code (I don't think <code>library(shinyWidgets)</code> is required, but just in case...):</p>
  <pre><code>library(shiny)
  library(shinyjs)
  library(tidyverse)
  
  ui &lt;-
    fluidPage(
      titlePanel(&quot;Test&quot;),
      sidebarLayout(
        sidebarPanel(
          useShinyjs(), # ATTEMPT
          selectInput(&quot;selectView&quot;, h5(strong(&quot;Select view:&quot;)), 
                       choices = list(&quot;Summary&quot;,&quot;Strats&quot;), 
                       selected = &quot;Summary&quot;),
          hidden(uiOutput(&quot;stratPeriod&quot;)) # ATTEMPT
        ), # close sidebar panel
        mainPanel(
          tabsetPanel(
            tabPanel(&quot;Data&quot;,
              conditionalPanel(
                  condition = &quot;input.selectView == 'Strats'&quot;,       
                  h5(strong(&quot;Stratified data:&quot;)), tableOutput(&quot;stratData&quot;)
              ) # close conditional panel
            ) # close tab panel
          ) # close tabset panel
        ) # close main panel
      ) # close sidebar layout
    ) # close fluid page
  
  server &lt;- function(input, output, session) {
  
    dat &lt;- reactive({
      data.frame(
        ID = c(1,1,2,2,2,2,3,3,3,3),
        Period = c(&quot;2020-03&quot;, &quot;2020-04&quot;, &quot;2020-01&quot;, &quot;2020-02&quot;, &quot;2020-03&quot;, &quot;2020-04&quot;, &quot;2020-01&quot;, &quot;2020-02&quot;, &quot;2020-03&quot;, &quot;2020-04&quot;),
        Values_1 = c(-6, 26, 36, 46, 56, 86, 100, 10, 20, 30),
        Values_2 = c(-6, 13, 18, 46, 28, 43, 100, 10, 10, 30)
      )  
    })
    
    observeEvent(input$selectView == 'Strats',{shinyjs::show(&quot;stratPeriod&quot;)}) # ATTEMPT
    
    output$stratPeriod &lt;- renderUI({
      chc &lt;- unique(na.omit(dat()[[2]]))
      selectInput(inputId = &quot;stratPeriod&quot;, 
                  label = &quot;Choose point-in-time:&quot;,
                  choices = chc,
                  selected = chc[1])
    })
    
    output$stratData &lt;- renderTable({
      req(input$stratPeriod)
      filter_exp1 &lt;- parse(text=paste0(&quot;Period&quot;,  &quot;==&quot;, &quot;'&quot;,input$stratPeriod, &quot;'&quot;))
      dat_1 &lt;- reactive({dat() %&gt;% filter(eval(filter_exp1))})
      min &lt;- if (length(dat_1()[[&quot;Values_1&quot;]])&gt;0) min(dat_1()[[&quot;Values_1&quot;]], na.rm=TRUE) else Inf
      max &lt;- if (length(dat_1()[[&quot;Values_1&quot;]])&gt;0) max(dat_1()[[&quot;Values_1&quot;]], na.rm=TRUE) else Inf
      breaks &lt;- if(any(is.infinite(c(min,max)))) c(0, 10) else seq(min, max, length.out = 6) 
      tmp &lt;- dat() %&gt;% 
        filter(eval(filter_exp1)) %&gt;%
        mutate(Range = cut(!!sym(&quot;Values_1&quot;), breaks=breaks, include.lowest=TRUE, right = TRUE, dig.lab = 5)) %&gt;% 
        group_by(Range) %&gt;%
        summarise(Count = n(),Values = sum(!!sym(&quot;Values_1&quot;))) %&gt;%
        complete(Range, fill = list(Count = 0,Values = 0)) %&gt;% 
        ungroup %&gt;% 
        dplyr::select(everything(), Count, Values)
      tmp
    })
  
  }
  
  shinyApp(ui, server)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/3oldU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3oldU.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/6SxJJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6SxJJ.png" alt="enter image description here" /></a></p>