Skip to content

Commit 60b1e0c

Browse files
chore: add deprecation to passing non-string select choices
1 parent 2dbec08 commit 60b1e0c

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

shiny/ui/_input_select.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,12 @@ def _input_select_impl(
251251

252252
choices_ = _normalize_choices(choices)
253253

254+
if _contains_html(choices_):
255+
warn_deprecated(
256+
"Passing anything other than a string to `choices` parameter of "
257+
"`input_select()` and `input_selectize()` is deprecated."
258+
)
259+
254260
selected = restore_input(resolved_id, selected)
255261
if selected is None and not multiple:
256262
selected = _find_first_option(choices_)
@@ -332,6 +338,17 @@ def _normalize_choices(x: SelectChoicesArg) -> _SelectChoices:
332338
return x
333339

334340

341+
def _contains_html(x: _SelectChoices) -> bool:
342+
for v in x.values():
343+
if isinstance(v, Mapping):
344+
if _contains_html(cast(_OptGrpChoices, v)):
345+
return True
346+
else:
347+
if not isinstance(v, str):
348+
return True
349+
return False
350+
351+
335352
def _render_choices(
336353
x: _SelectChoices, selected: Optional[str | list[str]] = None
337354
) -> TagList:

0 commit comments

Comments
 (0)