title: Display multiple summary statistics depending on user selection
body: <p>I'm creating a shiny app where a user can select a state <code>parent_location</code> and a county <code>name</code> from two drop downs. They can also select a variable of interest <code>layer</code> which will then produce a summary statistics table. I've got my code working up to this point. </p>
  
  <p>What I need to do is select other similar counties (contained in the <code>cluster</code> column) and then display summary statistics for this county as well. I can't seem to figure out how to A) display multiple summary statistics tables and B) dynamically create a list of similar counties. </p>
  
  <p>Code that works</p>
  
  <pre><code>library(shiny)
  library(tidyverse)
  library(lubridate)
  
  eviction_county_2010 &lt;- read.csv("./eviction_county_2010.csv")
  
  ui &lt;- fluidPage(
    sliderInput(inputId = "year",
                label = "Select a Year:",
                min = 2010,
                max = 2016,
                value = 2010,
                step = 1),
  
    radioButtons(inputId = "layer",
                 label = "Select a Dataset to View:",
                 choices = c("Eviction Filing Rate"="eviction_filing_rate", "Percent Rent Burden"="rent_burden",
                             "Percent Renter Occupied"="pct_renter_occupied", "Poverty Rate"="poverty_rate")),
  
    selectInput(inputId = "state",
                label = "Select a State:",
                eviction_county_2010$parent_location),
    selectInput(inputId = "county",
                label = "Select a County:",
                choices = NULL),
    mainPanel(
      h2("Summary of the variable"),
      verbatimTextOutput("sum")
    )
  )
  
  server &lt;- function(input, output, session) {
  
    observe({
      x &lt;- filter(eviction_county_2010,parent_location == input$state) %&gt;%
        select(name)
      updateSelectInput(session,"county","Select a County:",choices = unique(x))}
    )
  
      output$sum &lt;- renderPrint({
        ec &lt;- eviction_county_2010 %&gt;%
          filter(parent_location == input$state) %&gt;%
          filter(name == input$county)
        summary(ec[,input$layer])
    })
  }
  
  # Run the application 
  shinyApp(ui = ui, server = server)
  </code></pre>
  
  <p>Code I've attempted for displaying for similar counties. It returns <code>Error in .getReactiveEnvironment()$currentContext(): Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.)</code> I'm not sure which part needs to be placed inside a reactive expression. </p>
  
  <pre><code>ui &lt;- fluidPage(
    sliderInput(inputId = "year",
                label = "Select a Year:",
                min = 2010,
                max = 2016,
                value = 2010,
                step = 1),
  
    radioButtons(inputId = "layer",
                 label = "Select a Dataset to View:",
                 choices = c("Eviction Filing Rate"="eviction_filing_rate", "Percent Rent Burden"="rent_burden",
                             "Percent Renter Occupied"="pct_renter_occupied", "Poverty Rate"="poverty_rate")),
  
    selectInput(inputId = "state",
                label = "Select a State:",
                eviction_county_2010$parent_location),
    selectInput(inputId = "county",
                label = "Select a County:",
                choices = NULL),
    mainPanel(
      h2("Summary of the variable"),
      verbatimTextOutput("sum")
    )
  )
  
  server &lt;- function(input, output, session) {
  
    ec &lt;- eviction_county_2010 %&gt;%
      filter(parent_location == input$state) %&gt;%
      filter(name == input$county)
    sel_clust &lt;- unique(ec$cluster)
    sim_cty &lt;- eviction_county_2010[ sample(which(eviction_county_2010$cluster == sel_clust), 4),]
    sim_cty &lt;- unique(sim_cty$GEOID)
    sim_cty &lt;- append(sim_cty, unique(ec$GEOID))
  
    observe({
      x &lt;- filter(eviction_county_2010,parent_location == input$state) %&gt;%
        select(name)
      updateSelectInput(session,"county","Select a County:",choices = unique(x))}
    )
  
      output$sum &lt;- renderPrint({
      df1 &lt;- eviction_county_2010 %&gt;%
        filter(GEOID == sim_cty[1])
      df2 &lt;- eviction_county_2010 %&gt;%
        filter(GEOID == sim_cty[2])
      df3 &lt;- eviction_county_2010 %&gt;%
        filter(GEOID == sim_cty[3])
      df4 &lt;- eviction_county_2010 %&gt;%
        filter(GEOID == sim_cty[4])
      df5 &lt;- eviction_county_2010 %&gt;%
        filter(GEOID == sim_cty[5])
      summary(df1[,input$layer])
      summary(df2[,input$layer])
      summary(df3[,input$layer])
      summary(df4[,input$layer])
      summary(df5[,input$layer])
    })
  }
  
  # Run the application 
  shinyApp(ui = ui, server = server)
  </code></pre>
  
  <p>Is this even possible? What am I doing wrong here?</p>