简体   繁体   English

Shiny 活性物质开关 dplyr 过滤器

[英]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 .我正在尝试使用shinyWidgetsmaterialSwitch来控制 dplyr 过滤器,该过滤器使用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.单击开关并将其设置为 TRUE 时,此代码有效。 However when it is in the default status of FALSE the table is not showing up at all.但是,当它处于默认状态 FALSE 时,表格根本不会显示。 How can I make sure the filtered_date() variable shows all data when the button is not clicked?如何确保filtered_date()变量在未单击按钮时显示所有数据?

req(FALSE) stops the event so req(input$status,input$switch) stops the event when the switch is FALSE. req(FALSE)停止事件,因此当开关为 FALSE 时req(input$status,input$switch)停止事件。

This is why you don't have no result.这就是为什么你没有结果。

To fix it change to req(input$status)要修复它,请更改为req(input$status)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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