title: r - create reactive filter that is applied to an uploaded csv file in shiny
body: <p>I'm trying to create a shiny app in which a user would be able to upload a .csv file, and then apply a filter on that dataframe and then make a plot using ggplot2. Unfortunately I stumbled upon a problem when trying to create a select input menu from a variable coming from the .csv that is supposed to be uploaded.</p>
  
  <p>To create a simple example we can export the <code>diamonds</code> dataset from <code>ggplot2</code> as a .csv file: </p>
  
  <pre><code>write.csv(diamonds, "diamonds.csv")
  </code></pre>
  
  <p>Then to create the shiny app:</p>
  
  <pre><code>library(shiny)
  library(shinyWidgets)
  library(ggplot2)
  
  ui &lt;- fluidPage(
      titlePanel("test shiny"),
  
      # Sidebar with a slider input for number of bins
      sidebarLayout(sidebarPanel(
          fileInput('file1', 'Choose file to upload',
                    accept = c(
                        'text/csv',
                        'text/comma-separated-values',
                        'text/tab-separated-values',
                        'text/plain',
                        '.csv',
                        '.tsv'
                    )
          ),
          tags$hr(),
          pickerInput(
              inputId = "caratx",
              label = "Choose carat",
              choices = c("Select all", unique(user_data$carat)),
              multiple = TRUE
          ),
          selectInput(
              inputId = "clarityx",
              label = "Choose distance: ",
              choices = unique(user_data$clarity)
          )
      ),
      mainPanel(plotOutput("endplot"))
      ))
  
  # Define server logic 
  server &lt;- function(input, output) {
  
      output$endplot &lt;- renderPlot({
          inFile &lt;- input$file1
  
          if (is.null(inFile))
              return(NULL)
  
          user_data &lt;- read.csv(inFile$datapath, header = T,
                                sep = ",", quote = input$quote)
  
          validate(
              need(input$entityx, 'Please select at least one carat'),
              need(input$indicatorx, 'Please select at least one clarity')
          )
  
          if (input$caratx %in% "Select all") {
              user_data &lt;- user_data %&gt;%
                  filter(carat %in% input$caratx)
          } else {
              user_data &lt;- user_data %&gt;%
                  filter(carat %in% input$caratx) %&gt;%
                  filter(clarity %in% input$clarityx) 
          }
  
          user_data %&gt;% 
              ggplot(aes(x = `cut`)) +
              geom_point(aes(y = price), color = "red") +
              geom_point(aes(y = depth), color = "blue")
          })
  }
  
  # Run the application 
  shinyApp(ui = ui, server = server)
  </code></pre>
  
  <p>This is the output:    </p>
  
  <pre><code>Error in unique(user_data$carat) : object 'user_data' not found
  </code></pre>
  
  <p>Is there a way to make this work ?</p>
  
  <p>Many thanks !</p>