You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ui.update_radio_buttons doesn't allow for no selection unless choices field is provided #2400
I'm not sure if this is working as intended but I'm trying to update an input_radio_button group that is dependent on another radio button group. My intention is that whenever another button in a different radio group is selected the currently selected radio button is none. The only way to achieve this when calling ui.update_radio_buttons() is to provide the choices parameter and the selected = "". I would have thought to have no selection you could simply enter selected = "" but it does not update the selected field
It is on the client. RadioInputBinding.setValue only clears the group when it receives an empty array; anything else is treated as a value to look up by selector (srcts/src/bindings/input/radio.ts):
With selected="" the selector becomes [value=""], which matches no radio, so .prop("checked", true) is applied to an empty set. Nothing is unchecked and the previous selection survives.
The Python side forwards "" faithfully — _update_choice_input builds {"value": selected} and drop_none() only strips None, so "" does reach the browser. It just does not mean anything there.
Passing choices= works only incidentally: that branch regenerates the entire options HTML (with no checked attribute) and replaces the DOM, which clears the selection as a side effect.
Suggested fix
Either treat an empty string as "clear" in setValue:
or normalize on the Python side in _update_choice_input (map selected == "" to []). The first also fixes update_checkbox_group, which routes through the same binding shape.
Whichever way it goes, update_radio_buttons' selected parameter is currently typed Optional[str], so the working workaround (selected=[]) is not expressible without a type-checker complaint — worth widening the annotation or documenting the supported "clear" sentinel.
Verified against shiny 1.7.1.dev6 / py-shiny main.
This repo is the documentation site; the behavior is in the shiny package itself, so this should be moved to posit-dev/py-shiny.
Activity
schloerke commentedon Aug 1, 2026
Confirmed — this is not working as intended, and there is a one-word workaround: pass
selected=[]instead ofselected="".Reprex
Clicking each button in turn (fresh reload before each):
Root cause
It is on the client.
RadioInputBinding.setValueonly clears the group when it receives an empty array; anything else is treated as a value to look up by selector (srcts/src/bindings/input/radio.ts):With
selected=""the selector becomes[value=""], which matches no radio, so.prop("checked", true)is applied to an empty set. Nothing is unchecked and the previous selection survives.The Python side forwards
""faithfully —_update_choice_inputbuilds{"value": selected}anddrop_none()only stripsNone, so""does reach the browser. It just does not mean anything there.Passing
choices=works only incidentally: that branch regenerates the entire options HTML (with nocheckedattribute) and replaces the DOM, which clears the selection as a side effect.Suggested fix
Either treat an empty string as "clear" in
setValue:or normalize on the Python side in
_update_choice_input(mapselected == ""to[]). The first also fixesupdate_checkbox_group, which routes through the same binding shape.Whichever way it goes,
update_radio_buttons'selectedparameter is currently typedOptional[str], so the working workaround (selected=[]) is not expressible without a type-checker complaint — worth widening the annotation or documenting the supported "clear" sentinel.Verified against
shiny1.7.1.dev6 / py-shinymain.This repo is the documentation site; the behavior is in the
shinypackage itself, so this should be moved to posit-dev/py-shiny.schloerke commentedon Aug 1, 2026
Thank you for the Issue, @nvd2291 !