title: Filter dataframe by factors based on users input in Shiny
body: <p>I want the user of my shinyApp to select a variable, as well as the factors for this variable.</p>
  <p>Then, the shinyApp will provide a dataset where the factors are filtered.</p>
  <pre><code># Shiny
  library(shiny)
  library(shinyWidgets)
  library(shinyjqui)
  library(shinyjs)
  
  # Data
  library(readxl)
  library(dplyr)
  library(rlang)
  
  # Plots
  library(ggplot2)
  
  not_sel &lt;- &quot;Not Selected&quot;
  
  ui &lt;- navbarPage(
      tabPanel(
          &quot;&quot;,
          fluidPage(
              fluidRow(
                  sidebarPanel(
                      title = &quot;Inputs&quot;,
                      fileInput(&quot;xlsx_input&quot;, &quot;Select XLSX file to import&quot;, accept = c(&quot;.xlsx&quot;)),
                      selectInput(&quot;num_var_1&quot;, &quot;Variable X axis&quot;, choices = c(not_sel)),
                      selectInput(&quot;num_var_2&quot;, &quot;Variable Y axis&quot;, choices = c(not_sel)),
                      uiOutput(&quot;binning&quot;)
                  ),
                  
                  # Main panel
                  mainPanel(
                      tabsetPanel(
                          tabPanel(
                              &quot;Plot&quot;,
                              br(),
                              plotOutput(&quot;plot_1&quot;),
                              textOutput(&quot;test&quot;),
                              uiOutput(&quot;levels&quot;)
                          ) 
                      )
                  )
              )
          )
      )
  )
  
  server &lt;- function(input, output){
      
      # Load data and update inputs
      data_input &lt;- reactive({
          #req(input$xlsx_input)
          #inFile &lt;- input$xlsx_input
          #read_excel(inFile$datapath, 1)
          warpbreaks
      })
      
      observeEvent(data_input(),{
          choices &lt;- c(not_sel, names(data_input()))
          updateSelectInput(inputId = &quot;num_var_1&quot;, choices = choices)
          updateSelectInput(inputId = &quot;num_var_2&quot;, choices = choices)
      })
      
      num_var_1 &lt;- reactive(input$num_var_1)
      num_var_2 &lt;- reactive(input$num_var_2)
      
      # Select factors to display
      output$levels &lt;-  renderUI({
          req(data_input(), input$num_var_1)
          e &lt;- unique(data_input()[[input$num_var_1]])
          awesomeCheckboxGroup(inputId=&quot;levels&quot;, label = &quot;Factor level order&quot;, choices = setNames(as.numeric(e), e), inline = TRUE)
      })
      
      data_plot &lt;- reactive({
          req(data_input(), input$num_var_1, input$num_var_2)
          #df &lt;- data_input()
          df&lt;- data_input()[data_input()[[input$num_var_1]] %in% input$levels, ]
          df
      })
      
      output$test &lt;- renderPrint(data_input())
  }
  
  # Connection for the shinyApp
  shinyApp(ui = ui, server = server)
  </code></pre>
  <p>However, the filtering function is not working, and I don't see why.
  More precisely, this line of code:</p>
  <pre><code>df&lt;- data_input()[data_input()[[input$num_var_1]] %in% input$levels, ]
  </code></pre>
  <p>In the case of the attached image, for example, the dataset should have the values for the factor F.</p>
  <p>However, nothing is printed.</p>
  <p><a href="https://i.stack.imgur.com/iFfod.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iFfod.png" alt="enter image description here" /></a></p>