Skip to content
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Bug fixes

* Fixed missing selectize options when using a module and specifying `options`. (#1703)

* 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)
Expand Down
14 changes: 6 additions & 8 deletions shiny/ui/_input_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,15 +728,13 @@ def update_selectize(
)

if options is not None:
cfg = TagList(
tags.script(
json.dumps(options),
type="application/json",
data_for=id,
data_eval=json.dumps(extract_js_keys(options)),
)
cfg = tags.script(
json.dumps(options),
type="application/json",
data_for=resolve_id(id),
data_eval=json.dumps(extract_js_keys(options)),
)
session.send_input_message(id, drop_none({"config": cfg.get_html_string()}))
session.send_input_message(id, {"config": cfg.get_html_string()})

# Transform choices to a list of dicts (this is the form the client wants)
# [{"label": "Foo", "value": "foo", "optgroup": "foo"}, ...]
Expand Down
30 changes: 30 additions & 0 deletions tests/playwright/shiny/components/selectize/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from shiny import App, Inputs, Outputs, Session, module, reactive, ui


@module.ui
def reprex_selectize_ui():
return ui.input_selectize("x", "Server side selectize", choices=[], multiple=True)


@module.server
def reprex_selectize_server(
input: Inputs, output: Outputs, session: Session, starting_value: int = 0
):
@reactive.effect
def _():
ui.update_selectize(
"x",
choices=[f"Foo {i}" for i in range(3)],
server=False,
options={"placeholder": "Search"},
)


app_ui = ui.page_fluid(reprex_selectize_ui("reprex_selectize"))


def server(input: Inputs, output: Outputs, session: Session):
reprex_selectize_server("reprex_selectize")


app = App(app_ui, server, debug=True)
15 changes: 15 additions & 0 deletions tests/playwright/shiny/components/selectize/test_selectize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# import pytest
from playwright.sync_api import Page

from shiny.playwright import controller
from shiny.run import ShinyAppProc


def test_selectize(page: Page, local_app: ShinyAppProc) -> None:
page.goto(local_app.url)

selectize_menu = controller.InputSelectize(page, "reprex_selectize-x")
selectize_menu.expect_choices(["Foo 0", "Foo 1", "Foo 2"])
selectize_menu.expect_multiple(True)
selectize_menu.set(["Foo 0", "Foo 1"])
selectize_menu.expect_selected(["Foo 0", "Foo 1"])
Loading