Skip to content

Commit ce79a5f

Browse files
committed
Bugfix and add test
1 parent 0088ff4 commit ce79a5f

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

shiny/session/_session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ class Session(ABC):
188188
groups: list[str] | None
189189

190190
# Internal state for current_output_id()
191-
_current_output_id: str | None
191+
_current_output_id: str | None = None
192192

193193
# TODO: not sure these should be directly exposed
194194
_outbound_message_queues: OutBoundMessageQueues
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from shiny import App, Inputs, Outputs, Session, render, ui
2+
3+
app_ui = ui.page_fluid(
4+
ui.input_dark_mode(mode="light", id="dark_mode"),
5+
ui.output_text("text1"),
6+
ui.output_text("text2"),
7+
ui.output_text("info").add_class("shiny-report-theme"),
8+
)
9+
10+
11+
def server(input: Inputs, output: Outputs, session: Session):
12+
13+
@render.text
14+
def text1():
15+
id = session.current_output_id() or "None"
16+
return f"Output ID: {id}"
17+
18+
@output(id="text2")
19+
@render.text
20+
def _():
21+
id = session.current_output_id() or "None"
22+
return f"Output ID: {id}"
23+
24+
@render.text
25+
def info():
26+
bg_color = session.clientdata.output_bg_color()
27+
return f"BG color: {bg_color}"
28+
29+
30+
app = App(app_ui, server)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from playwright.sync_api import Page
2+
3+
from shiny.playwright import controller
4+
from shiny.run import ShinyAppProc
5+
6+
7+
def test_current_output_info(page: Page, local_app: ShinyAppProc) -> None:
8+
9+
page.goto(local_app.url)
10+
11+
# Check that the output ID is displayed correctly in the UI
12+
text1 = controller.OutputText(page, "text1")
13+
text2 = controller.OutputText(page, "text2")
14+
15+
text1.expect_value("Output ID: text1")
16+
text2.expect_value("Output ID: text2")
17+
18+
# Check that we can get background color from clientdata
19+
info = controller.OutputText(page, "info")
20+
info.expect_value("BG color: rgb(255, 255, 255)")
21+
22+
# Click the dark mode button to change the background color
23+
dark_mode = controller.InputDarkMode(page, "dark_mode")
24+
dark_mode.expect_mode("light")
25+
dark_mode.click()
26+
dark_mode.expect_mode("dark")
27+
28+
# Check that the background color has changed
29+
info.expect_value("BG color: rgb(29, 31, 33)")

0 commit comments

Comments
 (0)