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)