title: Shiny plots based on condition
body: <p>I'm a bit perplexed on this and have been searching and reading for the better part of the morning. Have tried a few things but can't seem to get it correct.</p>
  <p>I'm attempting to make a <code>shiny</code> plot that creates a <code>ggplot</code> based on <code>ui</code> selected inputs.</p>
  <p>Here's an example of what I'm working with:</p>
  <pre><code>library(tidyverse)
  library(shiny)
  library(shinyWidgets)
  
  subject &lt;- c(&quot;A&quot;, &quot;A&quot;, &quot;A&quot;, &quot;B&quot;, &quot;B&quot;, &quot;B&quot;, &quot;C&quot;, &quot;C&quot;, &quot;C&quot;, &quot;D&quot;, &quot;D&quot;, &quot;D&quot;, &quot;E&quot;, &quot;E&quot;)
  grp &lt;- c(rep(&quot;One&quot;, times = 6), rep(&quot;Two&quot;, times = 8))
  date &lt;- c(rep(c(&quot;8/1/2020&quot;, &quot;8/2/2020&quot;, &quot;8/3/2020&quot;), times = 4), &quot;8/1/2020&quot;, &quot;8/2/2020&quot;)
  var &lt;- round(rnorm(n = length(subject), mean = 0, sd = 2), 3)
  
  df &lt;- data.frame(subject, grp, date, var)
  df$date &lt;- as.Date(df$date, &quot;%m/%d/%Y&quot;)
  </code></pre>
  <p>I define my <code>ui</code> based on the selections I want in order: Date, Group, Subject, with the option to plot multiple subjects:</p>
  <h1>UI</h1>
  <pre><code>ui &lt;- fluidPage(
    
    selectInput(inputId = &quot;date&quot;,
                label = &quot;date&quot;,
                choices = df %&gt;% distinct(date) %&gt;% pull(date),
                selected = min(df$date)),
    
    selectInput(inputId = &quot;grp&quot;,
                label = &quot;grp&quot;,
                choices = df %&gt;% distinct(grp) %&gt;% pull(grp),
                selected = &quot;One&quot;),
    
    selectizeInput(inputId = &quot;subject&quot;,
                label = &quot;subject&quot;,
                choices = df %&gt;% distinct(subject) %&gt;% pull(subject),
                multiple = T),
    
    plotOutput(outputId = &quot;plt&quot;)
  )
  </code></pre>
  <p>In my <code>server</code> I attempt to do two filters. The first filter is to get the date and group. the second is to then only select the subjects in the selected group. Unfortunately, <code>shiny</code> retains all subjects.</p>
  <h1>Server</h1>
  <pre><code>server &lt;- function(input, output){
    
    output1 &lt;- reactive({
      d &lt;- df %&gt;%
        filter(date == input$date,
               (grp == input$grp))
      d
    })
    
    output2 &lt;- reactive({
      d &lt;- output1() %&gt;%
        filter(grp == input$grp &amp;
                 subject %in% input$subject)
      d
    })
    
    output$plt &lt;- renderPlot({
      d &lt;- output2()
      
      plt &lt;- d %&gt;%
        ggplot(aes(x = subject, y = var)) +
        geom_col()
      
      plt
    })
    
  }
  
  
  shinyApp(ui, server)
  </code></pre>
  <p>I feel like what I have above is pretty straight forward but I can't sort out why it wont return what I want. Thanks.</p>