在R中通过复选框GroupInput选择多列

在R中通过复选框GroupInput选择多列,r,checkbox,shiny,grepl,R,Checkbox,Shiny,Grepl,我有一个问题,关于如何通过R中的checkboxGroupInput选择数据集中的多个列 现在,我的数据集有如下列:(模式是stateName/number/number) 个人姓名 SA/111111/22222 VIC/33333/4444 新南威尔士州/55555/666666 QLD/7777/88888 我有一个很好用的选择框。我使用grepl提取状态名,并且我可以成功地选择单个状态 用户界面: 服务器: entities_state <- entities[ with(ent

我有一个问题,关于如何通过R中的checkboxGroupInput选择数据集中的多个列

现在,我的数据集有如下列:(模式是stateName/number/number)

个人姓名

SA/111111/22222

VIC/33333/4444

新南威尔士州/55555/666666

QLD/7777/88888

我有一个很好用的选择框。我使用grepl提取状态名,并且我可以成功地选择单个状态

用户界面:

服务器:

entities_state <- entities[ with(entities, grepl(input$select_state, c(entities$IndividualName))), ]

entities\u state可以使用
paste
collapse
一起创建
grepl
模式
,这样它将检查使用
select\u state
选择的任何一个选项

i1 <- grepl(paste(input$select_state, collapse="|"), entities$IndividualName)
library(dplyr)
entities %>%
           filter(i1)

如果需要部分匹配,可以直接使用
grepl
而不是%
中的
%。i、 e.
filter(entities,grepl(input$select_state,IndividualName))
但是,条件看起来是一样的,只是您之前使用了
base R
语法,并将其更改为
dplyr::filter
entities\u说明该语法有什么问题谢谢!阿克伦。在我将代码更改为
dplyr::filter(entities,grepl(input$select\u state,IndividualName))
之后,出现了一个问题。当我选择所有状态时,我的数据集只显示带有SA的行。然后我取消选择SA,数据集显示带有VIC的行。然后我取消选择VIC,数据集显示新南威尔士州的行。。。。。。我无法获取具有多个状态的行。我希望我能描述清楚。我认为在
选择input
中,您需要
multiple=TRUE
entities_state <-filter(entities, IndividualName %in% input$select_state)
i1 <- grepl(paste(input$select_state, collapse="|"), entities$IndividualName)
library(dplyr)
entities %>%
           filter(i1)
entities %>% 
         filter(grepl(paste(input$select_state, collapse="|"), IndividualName))