繁体   English   中英

在R Shiny中通过checkboxGroupInput选择多个列

[英]select multiple columns by checkboxGroupInput in R shiny

我有一个问题,如何在R Shiny中通过checkboxGroupInput在数据集中选择多个列。

现在我的数据集有一个像这样的列:(模式为stateName / number / number)

个人名

SA / 111111/222222

VIC / 33333/444444

新南威尔士州/ 55555/666666

QLD / 777777/888888

.....

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

用户界面:

        selectInput("select_state", h3("Select State"),
                choices = list("All States"="SA|VIC|NSW|QLD|WA|TAS|NT|ACT|CTH","South Australia"="SA",
                               "Victoria"="VIC","New South Wales"="NSW","Queensland"="QLD",
                               "Western Australia"="WA","Northern Territory"="NT","Tasmania"="TAS",
                               "Australian Capital Territory"="ACT","Commonwealth"="CTH")),

服务器:

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

现在我想将选择框更改为复选框组,我知道要使用复选框组,我们可以编写

entities_state <-filter(entities, IndividualName %in% input$select_state)

但我仍然需要从“ IndividualName”列中提取stateName关键字。 我不知道如何结合使用grepl,filter和%n%来使复选框组起作用。

我希望我清楚地表达我的问题。 如果没有,请告诉我。

patterngrepl可以使用进行paste ,并collapse| 这样它将检查使用select_state选择的选项之一

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

或者我们可以在filter创建它

entities %>% 
         filter(grepl(paste(input$select_state, collapse="|"), IndividualName))

暂无
暂无

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

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