From 75d4b0322021803c3bd642caf78d6a89f80a23a6 Mon Sep 17 00:00:00 2001 From: Liz Nelson Date: Fri, 1 Aug 2025 11:26:11 -0400 Subject: [PATCH 1/9] Debugging --- shiny/api-examples/update_selectize/app-core.py | 2 +- shiny/ui/_input_select.py | 4 +++- shiny/ui/_input_update.py | 15 ++++++++++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/shiny/api-examples/update_selectize/app-core.py b/shiny/api-examples/update_selectize/app-core.py index 31b83a501..3cbd4f0ee 100644 --- a/shiny/api-examples/update_selectize/app-core.py +++ b/shiny/api-examples/update_selectize/app-core.py @@ -10,7 +10,7 @@ def server(input: Inputs, output: Outputs, session: Session): def _(): ui.update_selectize( "x", - choices=[f"Foo {i}" for i in range(10000)], + choices=[f"Foo & {i}" for i in range(20)], selected=["Foo 0", "Foo 1"], server=True, ) diff --git a/shiny/ui/_input_select.py b/shiny/ui/_input_select.py index 4d144b3ca..b391b927f 100644 --- a/shiny/ui/_input_select.py +++ b/shiny/ui/_input_select.py @@ -220,7 +220,9 @@ def input_select( ) resolved_id = resolve_id(id) - + print( + "input_select, label: ", label, " choices: ", choices, " selected: ", selected + ) x = _input_select_impl( id=resolved_id, label=label, diff --git a/shiny/ui/_input_update.py b/shiny/ui/_input_update.py index 80b0255e9..bf048f45b 100644 --- a/shiny/ui/_input_update.py +++ b/shiny/ui/_input_update.py @@ -728,7 +728,14 @@ def update_selectize( return update_select( id, label=label, choices=choices, selected=selected, session=session ) - + print( + "Update Selectize s1: label:", + label, + " choices: ", + choices[0:10], + " selected: ", + selected, + ) if options is not None: cfg = TagList( tags.script( @@ -742,14 +749,20 @@ def update_selectize( # Transform choices to a list of dicts (this is the form the client wants) # [{"label": "Foo", "value": "foo", "optgroup": "foo"}, ...] + + # TODO: This is where the choices are getting too escaped + flat_choices: list[FlatSelectChoice] = [] if choices is not None: for k, v in _normalize_choices(choices).items(): if not isinstance(v, Mapping): + print("in if: ", k, v) + print(session._process_ui(v)) flat_choices.append( FlatSelectChoice(value=k, label=session._process_ui(v)["html"]) ) else: # The optgroup case + print("in else: ", k, v) flat_choices.extend( [ FlatSelectChoice( From ec0101781d8bd97a4d0b061ceed21ace785bbf98 Mon Sep 17 00:00:00 2001 From: Liz Nelson Date: Tue, 5 Aug 2025 12:16:30 -0400 Subject: [PATCH 2/9] Removing HTML vals and messaging --- shiny/ui/_input_select.py | 8 +------- shiny/ui/_input_update.py | 26 +++++--------------------- 2 files changed, 6 insertions(+), 28 deletions(-) diff --git a/shiny/ui/_input_select.py b/shiny/ui/_input_select.py index b391b927f..5239e065c 100644 --- a/shiny/ui/_input_select.py +++ b/shiny/ui/_input_select.py @@ -21,7 +21,7 @@ from ._html_deps_external import selectize_deps from ._utils import JSEval, extract_js_keys, shiny_input_label -_Choices = Mapping[str, TagChild] +_Choices = Mapping[str, str] _OptGrpChoices = Mapping[str, _Choices] # Canonical format for representing select options. @@ -261,12 +261,6 @@ def _input_select_impl( choices_ = _normalize_choices(choices) - if _contains_html(choices_): - warn_deprecated( - "Passing anything other than a string to `choices` parameter of " - "`input_select()` and `input_selectize()` is deprecated." - ) - selected = restore_input(resolved_id, selected) if selected is None and not multiple: selected = _find_first_option(choices_) diff --git a/shiny/ui/_input_update.py b/shiny/ui/_input_update.py index bf048f45b..1771416d1 100644 --- a/shiny/ui/_input_update.py +++ b/shiny/ui/_input_update.py @@ -628,8 +628,8 @@ def update_select( An input label. choices Either a list of choices or a dictionary mapping choice values to labels. Note - that if a dictionary is provided, the keys are used as the (input) values so - that the dictionary values can hold HTML labels. A dictionary of dictionaries is + that if a dictionary is provided, the keys are used as the (input) values.It is not recommended to use + anything other than a string for these labels. A dictionary of dictionaries is also supported, and in that case, the top-level keys are treated as ```` labels. selected @@ -728,14 +728,7 @@ def update_selectize( return update_select( id, label=label, choices=choices, selected=selected, session=session ) - print( - "Update Selectize s1: label:", - label, - " choices: ", - choices[0:10], - " selected: ", - selected, - ) + if options is not None: cfg = TagList( tags.script( @@ -750,24 +743,15 @@ def update_selectize( # Transform choices to a list of dicts (this is the form the client wants) # [{"label": "Foo", "value": "foo", "optgroup": "foo"}, ...] - # TODO: This is where the choices are getting too escaped - flat_choices: list[FlatSelectChoice] = [] if choices is not None: for k, v in _normalize_choices(choices).items(): if not isinstance(v, Mapping): - print("in if: ", k, v) - print(session._process_ui(v)) - flat_choices.append( - FlatSelectChoice(value=k, label=session._process_ui(v)["html"]) - ) + flat_choices.append(FlatSelectChoice(value=k, label=v)) else: # The optgroup case - print("in else: ", k, v) flat_choices.extend( [ - FlatSelectChoice( - optgroup=k, value=k2, label=session._process_ui(v2)["html"] - ) + FlatSelectChoice(optgroup=k, value=k2, label=v2) for (k2, v2) in v.items() ] ) From 63ee9a7931fae470dedd93ff800926bd2a1b1bc1 Mon Sep 17 00:00:00 2001 From: Liz Nelson Date: Tue, 5 Aug 2025 12:49:28 -0400 Subject: [PATCH 3/9] Reverting testing changes --- shiny/api-examples/update_selectize/app-core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shiny/api-examples/update_selectize/app-core.py b/shiny/api-examples/update_selectize/app-core.py index 3cbd4f0ee..31b83a501 100644 --- a/shiny/api-examples/update_selectize/app-core.py +++ b/shiny/api-examples/update_selectize/app-core.py @@ -10,7 +10,7 @@ def server(input: Inputs, output: Outputs, session: Session): def _(): ui.update_selectize( "x", - choices=[f"Foo & {i}" for i in range(20)], + choices=[f"Foo {i}" for i in range(10000)], selected=["Foo 0", "Foo 1"], server=True, ) From ff6af02325fc2300c98e6f757bc4c4c0d2c8fa6f Mon Sep 17 00:00:00 2001 From: Liz Nelson Date: Tue, 5 Aug 2025 12:49:53 -0400 Subject: [PATCH 4/9] Reverting testing changes --- shiny/ui/_input_select.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/shiny/ui/_input_select.py b/shiny/ui/_input_select.py index 5239e065c..c957e0817 100644 --- a/shiny/ui/_input_select.py +++ b/shiny/ui/_input_select.py @@ -220,9 +220,7 @@ def input_select( ) resolved_id = resolve_id(id) - print( - "input_select, label: ", label, " choices: ", choices, " selected: ", selected - ) + x = _input_select_impl( id=resolved_id, label=label, From 5571ba07d65a8b9c3bdf5abe06b4c4258508e854 Mon Sep 17 00:00:00 2001 From: E Nelson Date: Tue, 5 Aug 2025 13:01:24 -0400 Subject: [PATCH 5/9] Update shiny/ui/_input_update.py --- shiny/ui/_input_update.py | 1 - 1 file changed, 1 deletion(-) diff --git a/shiny/ui/_input_update.py b/shiny/ui/_input_update.py index 1771416d1..265c5765f 100644 --- a/shiny/ui/_input_update.py +++ b/shiny/ui/_input_update.py @@ -742,7 +742,6 @@ def update_selectize( # Transform choices to a list of dicts (this is the form the client wants) # [{"label": "Foo", "value": "foo", "optgroup": "foo"}, ...] - flat_choices: list[FlatSelectChoice] = [] if choices is not None: for k, v in _normalize_choices(choices).items(): From 36defe1f03a072365c2b60ab586dae0149cdb414 Mon Sep 17 00:00:00 2001 From: Liz Nelson Date: Tue, 5 Aug 2025 14:53:37 -0400 Subject: [PATCH 6/9] Updating changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab2aa6f47..aa340e19d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Improvements +* Removed statement that you could pass HTML into `update_selectize` choices. This never worked. Please use `options.render` (see example under `input_selectize`). (#2048) + * Improved the styling and readability of markdown tables rendered by `ui.Chat()` and `ui.MarkdownStream()`. (#1973) * `selectize`, `remove_button`, and `options` parameters of `ui.input_select()` have been deprecated; use `ui.input_selectize()` instead. (Thanks, @ErdaradunGaztea!) (#1947) From a07c97a6da40ccdd108535762d7d044b1f6ccd5a Mon Sep 17 00:00:00 2001 From: E Nelson Date: Wed, 6 Aug 2025 09:42:43 -0400 Subject: [PATCH 7/9] Update shiny/ui/_input_update.py Co-authored-by: Carson Sievert --- shiny/ui/_input_update.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/shiny/ui/_input_update.py b/shiny/ui/_input_update.py index 265c5765f..850d5a810 100644 --- a/shiny/ui/_input_update.py +++ b/shiny/ui/_input_update.py @@ -628,8 +628,7 @@ def update_select( An input label. choices Either a list of choices or a dictionary mapping choice values to labels. Note - that if a dictionary is provided, the keys are used as the (input) values.It is not recommended to use - anything other than a string for these labels. A dictionary of dictionaries is + that if a dictionary is provided, the keys are used as the (input) values. A dictionary of dictionaries is also supported, and in that case, the top-level keys are treated as ```` labels. selected From c55fcd2fe3cf925fc53328a96331bd991e19a3ba Mon Sep 17 00:00:00 2001 From: Liz Nelson Date: Wed, 6 Aug 2025 09:52:55 -0400 Subject: [PATCH 8/9] Docstring updates --- shiny/ui/_input_select.py | 6 ++---- shiny/ui/_input_update.py | 3 +-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/shiny/ui/_input_select.py b/shiny/ui/_input_select.py index c957e0817..5bce83be4 100644 --- a/shiny/ui/_input_select.py +++ b/shiny/ui/_input_select.py @@ -75,8 +75,7 @@ def input_selectize( choices Either a list of choices or a dictionary mapping choice values to labels. Note that if a dictionary is provided, the keys are used as the (input) values and - the values are labels displayed to the user. It is not recommended to use - anything other than a string for these labels. A dictionary of dictionaries is + the values are labels displayed to the user. A dictionary of dictionaries is also supported, and in that case, the top-level keys are treated as ```` labels. selected @@ -157,8 +156,7 @@ def input_select( choices Either a list of choices or a dictionary mapping choice values to labels. Note that if a dictionary is provided, the keys are used as the (input) values and - the values are labels displayed to the user. It is not recommended to use - anything other than a string for these labels. A dictionary of dictionaries is + the values are labels displayed to the user. A dictionary of dictionaries is also supported, and in that case, the top-level keys are treated as ```` labels. selected diff --git a/shiny/ui/_input_update.py b/shiny/ui/_input_update.py index 850d5a810..cad0af229 100644 --- a/shiny/ui/_input_update.py +++ b/shiny/ui/_input_update.py @@ -696,8 +696,7 @@ def update_selectize( An input label. choices Either a list of choices or a dictionary mapping choice values to labels. Note - that if a dictionary is provided, the keys are used as the (input) values so - that the dictionary values can hold HTML labels. A dictionary of dictionaries is + that if a dictionary is provided, the keys are used as the (input) values. A dictionary of dictionaries is also supported, and in that case, the top-level keys are treated as ```` labels. selected From ebdf848ef5b70ce22ee273770cde085fdbc6f981 Mon Sep 17 00:00:00 2001 From: Liz Nelson Date: Wed, 6 Aug 2025 09:54:55 -0400 Subject: [PATCH 9/9] Updated text --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa340e19d..ee42b9ed3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,7 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Improvements -* Removed statement that you could pass HTML into `update_selectize` choices. This never worked. Please use `options.render` (see example under `input_selectize`). (#2048) +* Restricted the allowable types of the `choices` parameter of `input_select()`, `input_selectize()`, `update_select()`, and `update_selectize()` to actual set of allowable types (previously, the type was suggesting HTML-like values were supported). (#2048) * Improved the styling and readability of markdown tables rendered by `ui.Chat()` and `ui.MarkdownStream()`. (#1973) @@ -41,6 +41,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Bug fixes +* Fixed an issue with `update_selectize()` to properly display labels with HTML reserved characters like "&" (#1330) + * Fixed an issue with `ui.Chat()` sometimes wanting to scroll a parent element. (#1996) * Explicitly call out module usage in UI input bookmark button documentation. (#1983)