Skip to content

Docs: Clarify update*Input() selected behavior with NULL (#2144)#4397

Open
samuelbharti wants to merge 1 commit into
rstudio:mainfrom
samuelbharti:samuelbharti/review-shiny-issue-2144
Open

Docs: Clarify update*Input() selected behavior with NULL (#2144)#4397
samuelbharti wants to merge 1 commit into
rstudio:mainfrom
samuelbharti:samuelbharti/review-shiny-issue-2144

Conversation

@samuelbharti

Copy link
Copy Markdown
Contributor

Closes #2144

Summary

updateSelectInput()'s documentation was self-contradicting. The shared man-roxygen/update-input.R template stated that "Any arguments with NULL values will be ignored; they will not result in any changes to the input object on the client", but for choice-based inputs selected = NULL (the default) does not preserve the current selection — when choices is also being updated, the options are re-rendered with nothing selected. The inherited selected param doc also carried selectInput()'s constructor wording ("defaults to the first value..."), which is misleading for an updater.

This is a docs-only change with no behavior change. It generalizes the shared template so its first paragraph is accurate for all update*Input() functions ("Arguments with NULL values are generally ignored... See the per-argument documentation for any exceptions."). The previous wording named selected/choice-inputs in the shared template, which leaked an irrelevant sentence onto unrelated functions (updateSliderInput(), updateTextInput(), etc.) that have no selected argument. It then adds per-argument selected documentation to updateSelectInput() (shared via @rdname with the selectize/varSelect variants), updateCheckboxGroupInput(), and updateRadioButtons(), describing how NULL (no-op unless options are also updated), character(0) (clears the selection), and an explicit value behave, plus the server-side single-select selectize and radio "first choice" caveats.

All behavioral claims were verified against the actual sendInputMessage() payloads using a mock session.

Verification

The documented contract, confirmed by inspecting the message sent to the client via a mock session:

  • selected = NULL, no choices update -> empty message (no-op, selection preserved)
  • selected = NULL, with choices -> options re-rendered, none selected
  • selected = character(0), no choices -> value = character(0) (selection cleared)
  • updateRadioButtons(selected = NULL, choices = ...) -> first choice selected

Rendered help pages: ?updateSelectInput now describes updater semantics for selected; ?updateSliderInput (and other non-choice updaters) show only the clean generic paragraph with no stray selected reference.

The shared update-input template claimed that "Any arguments with NULL
values will be ignored", which contradicted the behavior of `selected`
for choice-based inputs: when `choices` is also updated, `selected = NULL`
resets the selection rather than preserving it.

Soften the shared template to a generic, accurate statement and add
per-argument `selected` documentation to updateSelectInput(),
updateCheckboxGroupInput(), and updateRadioButtons() describing how
`NULL`, `character(0)`, and an explicit value behave.
@samuelbharti samuelbharti marked this pull request as ready for review June 2, 2026 14:52
@cpsievert cpsievert requested a review from Copilot June 2, 2026 18:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates Shiny’s documentation to resolve contradictions around update*Input() handling of NULL arguments, with a focus on clarifying how selected = NULL behaves for choice-based inputs when options are re-rendered.

Changes:

  • Generalized the shared update*Input() docs to say NULL arguments are generally ignored, with per-argument exceptions.
  • Added/updated selected argument documentation for updateSelectInput()/updateSelectizeInput()/updateVarSelectInput(), updateCheckboxGroupInput(), and updateRadioButtons().
  • Added a NEWS entry describing the documentation clarification.

Reviewed changes

Copilot reviewed 3 out of 14 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
R/update-input.R Adds per-argument selected documentation for choice-based update*Input() functions.
man-roxygen/update-input.R Updates shared updater template wording about NULL handling.
NEWS.md Notes the documentation clarification for selected semantics.
man/updateSelectInput.Rd Updates selected argument and shared updater details text for select updaters.
man/updateCheckboxGroupInput.Rd Updates selected argument and shared updater details text for checkbox group updater.
man/updateRadioButtons.Rd Updates selected argument and shared updater details text for radio updater.
man/updateTextInput.Rd Regenerated to reflect updated shared template wording.
man/updateTextAreaInput.Rd Regenerated to reflect updated shared template wording.
man/updateSliderInput.Rd Regenerated to reflect updated shared template wording.
man/updateNumericInput.Rd Regenerated to reflect updated shared template wording.
man/updateDateInput.Rd Regenerated to reflect updated shared template wording.
man/updateDateRangeInput.Rd Regenerated to reflect updated shared template wording.
man/updateCheckboxInput.Rd Regenerated to reflect updated shared template wording.
man/updateActionButton.Rd Regenerated to reflect updated shared template wording.
Files not reviewed (11)
  • man/updateActionButton.Rd: Language not supported
  • man/updateCheckboxGroupInput.Rd: Language not supported
  • man/updateCheckboxInput.Rd: Language not supported
  • man/updateDateInput.Rd: Language not supported
  • man/updateDateRangeInput.Rd: Language not supported
  • man/updateNumericInput.Rd: Language not supported
  • man/updateRadioButtons.Rd: Language not supported
  • man/updateSelectInput.Rd: Language not supported
  • man/updateSliderInput.Rd: Language not supported
  • man/updateTextAreaInput.Rd: Language not supported
  • man/updateTextInput.Rd: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread R/update-input.R
Comment on lines +528 to +530
#' To preserve the current selection across a `choices` update, pass
#' `selected = input$id` explicitly. To clear the selection, pass
#' `selected = character(0)`.
Comment thread R/update-input.R
Comment on lines +584 to +586
#' first choice. To preserve the current selection across a `choices` update,
#' pass `selected = input$id` explicitly. To start with no item selected,
#' pass `selected = character(0)`.
Comment thread R/update-input.R
Comment on lines +639 to +645
#' does not preserve the current selection when the set of options is also
#' being updated (via `choices`, or `data` for the `varSelect` variants): the
#' options are re-rendered with none selected, except for server-side
#' single-select `updateSelectizeInput()`, which selects the first option. To
#' preserve the current selection across such an update, pass
#' `selected = input$id` explicitly. To clear the selection, pass
#' `selected = character(0)`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

updateSelectInput's documentation is self-contradicting with regards to "selected"

2 participants