Getting multiple checkbox values ​​in Shiny

I have a number of flags in the sidebar, which are defined as follows inside the sidebarPanel :

 sliderInput("days", "Days to monitor:", min = 1, max = 50, value = 5), checkboxInput("display_CMC", "Carolinas Medical Center", TRUE), checkboxInput("display_MariaParham", "Maria Parham", TRUE), checkboxInput("display_WakeMed", "Wake Med", TRUE) 

I would like to convert these results to a character vector programmatically (for example, if I had a checkboxInput named " display_ , I want it to automatically analyze the results). For this, I tried:

 displayIdx <- grep( "display_", names(input) ) facilityCode_keep <- names(input)[ displayIdx ][ input[ displayIdx ] ] 

Unfortunately, this leads to:

 Error: Single-bracket indexing of reactivevalues object is not allowed. 

Two questions:

  • How to convert checkboxInput series to character vector?
  • What happens when single parenthesis indexing is disabled. I could understand if I was trying to assign input , but I don't know.
+6
source share
1 answer

How to convert checkboxInputs sequence to character vector?

You can use double-bound indexing. But in this case, you can instead use the checkboxGroupInput function, which returns the character vector of the selected values.

Why not indexing with one bracket?

Indexing with one bracket is a subset, and indexing with two brackets is extracting elements (or something like that). The input object is more like map / hash / dict / environment than a named vector, so the subset does not really make sense. (In the same way, you cannot index single indices on objects in R, you can only use an index with two brackets.)

+9
source

Source: https://habr.com/ru/post/945441/


All Articles