简体   繁体   中英

Shiny Reactive materialSwitch dplyr filter

I am trying to use a materialSwitch from shinyWidgets to control a dplyr filter that catches text in a certain column using grepl .

Currently my code looks like this:

    pickerInput(
      inputId = "status",
      label = "Status:",
      choices = sort(unique(df$STATUS)),
      selected = unique(df$STATUS))
  
    materialSwitch(
       inputId = "switch",
       label = "TEXT", 
        value = FALSE,
       status = "primary"
    )

    filtered_data <-
        reactive ({
          req(input$status,
              input$switch)
          
          ready_for_reg %>% 
            filter(STATUS %in% input$status) %>%  
            filter(if(input$switch == TRUE) grepl("TEST",COL1) else TRUE )
           
    
        })

 DT::renderDataTable(datatable(filtered_data())

This code works when the switch is clicked and set to TRUE. However when it is in the default status of FALSE the table is not showing up at all. How can I make sure the filtered_date() variable shows all data when the button is not clicked?

req(FALSE) stops the event so req(input$status,input$switch) stops the event when the switch is FALSE.

This is why you don't have no result.

To fix it change to req(input$status)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM