title: How can I subset my dataframe based on the input of a checkbox in a shiny app?
body: <p>I am working on a shiny app, I am trying to filter a dataframe based in the input of a checkbox, it is, if the check box is clicked the dataframe is filtered, else dataframe remains the same. If the checkbox is selected only those rows with value "YES" must be select in the column 'CANONICAL'</p>
  
  <p>I have read similar questions (like here: <a href="https://stackoverflow.com/questions/32148144/condition-filter-in-dplyr-based-on-shiny-input/52934002#52934002">Condition Filter in dplyr based on Shiny input</a>)  but I haven't been able to solve mine.</p>
  
  <p>My code is as follows:</p>
  
  <pre><code>library(shiny)
  library(DT) 
  library(dplyr)
  library(shinyWidgets)
  
  options(shiny.maxRequestSize = 100*1024^2)
  
  ui &lt;- fluidPage(
  
    sidebarLayout(
  
      sidebarPanel(
        fileInput("file1", "Upload your File",
                  multiple = FALSE,
                  accept = c("text/csv",
                             "text/comma-separated-values,text/plain",
                             ".csv")),
  
        pickerInput("Consequence", "Consequence:",   
                    choices = c( "x", "y","z"), 
                    options = list(`actions-box` = TRUE),
                    multiple = TRUE ),
        prettyCheckbox(inputId= "CANONICAL", label = "CANONICAL", value =              FALSE, outline= TRUE, fill = TRUE, bigger = TRUE, status = 'success',width = NULL),
  
      mainPanel(
        dataTableOutput("contents")
      )
  
    ))
  
  server &lt;- function(input, output) {
  
    output$contents &lt;- renderDT({
      req(input$file1)
      df &lt;- read.delim(input$file1$datapath,
                       header = TRUE,
                       sep = '\t') 
  
      # Apply filters 
      df &lt;- df %&gt;% 
      filter(Consequence == input$Consequence ) %&gt;%
      { if (input$CANONICAL) filter( CANONICAL == 'YES') }
  
  return(df)
  
  shinyApp(ui, server) 
  </code></pre>
  
  <p>The last filter does not work either if the condition is <code>(input$CANONICAL)</code>, <code>(input$CANONICAL == TRUE)</code> or <code>(!is.null(input$CANONICAL))</code>. I have also tried to define the condition in a separate reactive function, but nothing seems to be working.</p>