lundi 25 juin 2018

select multiple columns by checkboxGroupInput in R shiny

I have a question about how to select multiple columns in my dataset by checkboxGroupInput in R shiny.

Now my dataset have a column like this: (the pattern is stateName/number/number)

IndividualName

SA/111111/222222

VIC/33333/444444

NSW/55555/666666

QLD/777777/888888

.....

and I have a select box that works well. I use grepl to extract state name and I can choose individual state successfully.

UI:

        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")),

Server:

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

Now I want to change the select box to checkbox group, I know to use checkbox group, we can write

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

but I still need extract stateName keyword from the "IndividualName" column. I don't know how to combine grepl, filter, and %n% to make the checkbox group work.

I hope I express my problem clearly. If not, please let me know.




Aucun commentaire:

Enregistrer un commentaire