Skip to content

Commit

Permalink
explicitly define updateSelectInput() instead of using the trick to c…
Browse files Browse the repository at this point in the history
…hange the `options` argument of updateInputOptions()
  • Loading branch information
yihui committed Jul 16, 2014
1 parent 262528e commit 0f0b0cd
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions R/update-input.R
Expand Up @@ -401,13 +401,13 @@ updateRadioButtons <- function(
updateSelectInput <- function(
session, inputId, label = NULL, choices = NULL, selected = NULL
) {
updateSelectInput2(session, inputId, label, choices, selected)
choices <- choicesWithNames(choices)
if (!is.null(selected))

This comment has been minimized.

Copy link
@wch

wch Jul 16, 2014

Collaborator

Should this choose the default selected item in the same way as selectInput?

Update: @yihui pointed out that, from this function, we don't know if it's a multiple select or not, so we can't correctly choose a default selected item. So we can just leave it to the user to set selected items, or not.

selected <- validateSelected(selected, choices, inputId)
options <- if (length(choices)) selectOptions(choices, selected)
message <- dropNulls(list(label = label, options = options, value = selected))
session$sendInputMessage(inputId, message)
}
# the reason for constructing this function is to assign a default value to the
# `options` argument of updateInputOptions(), and we want the evaluation of this
# argument to be delayed until `choices` has been named and `selected` validated
updateSelectInput2 <- updateInputOptions
formals(updateSelectInput2)['options'] <- alist(options = selectOptions(choices, selected))

#' @rdname updateSelectInput
#' @inheritParams selectizeInput
Expand Down

0 comments on commit 0f0b0cd

Please sign in to comment.