make sure the selected argument never contains names; fixes #428

This commit is contained in:
Yihui Xie
2014-05-20 01:31:14 -05:00
parent 3bdcdf96d4
commit 39b4805a76

View File

@@ -603,6 +603,8 @@ checkboxGroupInput <- function(inputId, label, choices, selected = NULL) {
# Before shiny 0.9, `selected` refers to names/labels of `choices`; now it
# refers to values. Below is a function for backward compatibility.
validateSelected <- function(selected, choices, inputId) {
# drop names, otherwise toJSON() keeps them too
selected <- unname(selected)
if (is.list(choices)) {
# <optgroup> is not there yet
if (any(sapply(choices, length) > 1)) return(selected)
@@ -615,7 +617,7 @@ validateSelected <- function(selected, choices, inputId) {
i <- (selected %in% nms) & !(selected %in% choices)
if (any(i)) {
warnFun <- if (all(i)) {
# replace names with values; drop names, otherwise toJSON() keeps them too
# replace names with values
selected <- unname(choices[selected])
warning
} else stop # stop when it is ambiguous (some labels == values)