title: Creating reactive renderUI
body: <p>I am following <a href="http://www.r-bloggers.com/building-shiny-apps-an-interactive-tutorial/" rel="nofollow">this tutorial</a> to learn to build Shiny apps. In the final version, the <code>renderUI()</code> for "Country" just takes all of the countries in the dataset. Is there a way to make this list reactive/filtered based on the price range selected with the slider?</p>
  
  <p>Here is the relevant code:</p>
  
  <pre><code>output$countryOutput &lt;- renderUI({
      selectInput("countryInput", "Country",
                  sort(unique(bcl$Country)),
                  selected="CANADA")
    })
  </code></pre>
  
  <p>And here is the entire. very simple app:</p>
  
  <pre><code>library(shiny)
  library(ggplot2)
  library(dplyr)
  
  bcl &lt;- read.csv("bcl-data.csv", stringsAsFactors = FALSE)
  
  ui &lt;- fluidPage(
           titlePanel("BC Liquor Prices", windowTitle = "Mmmmm yeh"),
           sidebarLayout(
             sidebarPanel(
               sliderInput("priceInput", "Price",
                           min = 0, max = 100,
                           value = c(25, 40), pre = "$"
                           ),
               radioButtons("typeInput", "Product type",
                            choices = c("BEER", "REFRESHMENT", "SPIRITS", "WINE"),
                            selected = "WINE"
                            ),
               uiOutput("countryOutput")
             ),
             mainPanel(plotOutput("coolplot"),
                       br(),
                       br(),
                       tableOutput("results")
                       )
             )
        )
  server &lt;- function(input, output, session) {
  
    filtered &lt;- reactive({
      if (is.null(input$countryInput)) {return(NULL)} 
  
      bcl %&gt;%
        filter(
          Price &gt;= input$priceInput[1],
          Price &lt;= input$priceInput[2],
          Type == input$typeInput,
          Country == input$countryInput
        )
    })
  
    output$countryOutput &lt;- renderUI({
      selectInput("countryInput", "Country",
                  sort(unique(bcl$Country)),
                  selected="CANADA")
    })
  
    output$coolplot &lt;- renderPlot({
      if (is.null(filtered())) {return()}
                        ggplot(filtered(), aes(Alcohol_Content)) + geom_histogram()
                      })
  
    output$results &lt;- renderTable({
                        filtered()
                      })
  }
  
  shinyApp(ui = ui, server = server)
  </code></pre>