How to build a dynamic filter in R Shiny?
<p>I am building an App with an upload function and a filter function for category variables. That way, users are able to do a bit of data manipulation by specifying columns and values. However, the filter function does not work. The code is simplified as following:</p>

<pre><code>#ui.R
library(shiny)

fluidPage(
  titlePanel("Test Dynamic Column Selection"),
  sidebarLayout(
    sidebarPanel(
      fileInput('file1', 'Choose CSV File',
            accept=c('text/csv', 
                     'text/comma-separated-values,text/plain', 
                     '.csv')),
      hr(),
      checkboxInput('header', 'Header', TRUE),
      radioButtons('sep', 'Separator',
               c(Comma=',',
                 Semicolon=';',
                 Tab='\t'),
               ','),
      hr(),
      uiOutput("choose_columns"),
      hr(),
      uiOutput("choose_column"),
      textInput('column_value', label = 'Value'),
      actionButton('filter', label = 'Filter')
    ),
    mainPanel(
      tableOutput('contents')
    )
  )
)

#server.R
library(shiny)

function(input, output) {

  uploaded_data &lt;- reactive({
    inFile &lt;- input$file1
    read.table(inFile$datapath, header=input$header, sep=input$sep, quote=input$quote)
  })

  react_vals &lt;- reactiveValues(data = NULL)

  output$choose_columns &lt;- renderUI({
    if(is.null(input$file1))
      return()

    colnames &lt;- names(react_vals$data)

    checkboxGroupInput("choose_columns", "Choose columns", 
                   choices  = colnames,
                   selected = colnames)
  })

  output$choose_column &lt;- renderUI({
    if(is.null(input$file1))
      return()
    is_factor &lt;- sapply(react_vals$data, is.factor)
    colnames &lt;- names(react_vals$data[, is_factor])
    selectInput("choose_column", "Choose column", choices = colnames)
  })

  observeEvent(input$file1, react_vals$data &lt;- uploaded_data())
  observeEvent(input$choose_columns, react_vals$data &lt;- react_vals$data[, input$choose_columns])

  # This line of code does not work :(
  observeEvent(input$filter, react_vals$data &lt;- subset(react_vals$data, input$choose_column != input$column_value))

  output$contents &lt;- renderTable(react_vals$data)
}
</code></pre>