I have a series of checkboxes in a side panel, defined as follows inside a 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'd like to transform those results into a character vector in a programmatic way (e.g. if I had a checkboxInput with a name 'display_
I want it to automatically parse the results). To do that, I tried:
displayIdx <- grep( "display_", names(input) )
facilityCode_keep <- names(input)[ displayIdx ][ input[ displayIdx ] ]
Unfortunately, that results in:
Error: Single-bracket indexing of reactivevalues object is not allowed.
Two questions:
checkboxInput
s into a character vector?input
, but I'm not.How do I transform a series of checkboxInputs into a character vector?
You can use double-bracket indexing. But in this case you might consider using checkboxGroupInput
function instead, which returns a character vector of the selected values.
Why not single-bracket indexing?
Single-bracket indexing is subsetting, while double-bracket indexing is element retrieval (or something like that). The input object is more like a map/hash/dict/environment than like a named vector, so subsetting doesn't really make sense. (Similarly, you can't single-bracket index on R's environment objects, you can only double-bracket index.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With