-
Notifications
You must be signed in to change notification settings - Fork 113
feat(clientdata): id
is now optional on clientdata.output_*()
methods
#1978
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
15be8ad
feat(session): Add a current_output_id attribute for identifying curr…
cpsievert abaebbb
feat(session.clientdata): allow output_*() methods to be called witho…
cpsievert e97b0f0
Update changelog
cpsievert cb9fdde
Appease import lint
cpsievert 7f3e958
Make sure context manager always yields
cpsievert 0908a4e
Make it a method instead of attribute. More careful cleanup
cpsievert 0088ff4
Tweak wording
cpsievert ce79a5f
Bugfix and add test
cpsievert 11e8a70
Import lint
cpsievert 1a9ed7f
Address feedback
cpsievert 95cdc59
Merge branch 'main' into feat/current_output_id
cpsievert 6b07a8e
Update tests
cpsievert 5866600
Run isort
cpsievert 4de9a7f
Fix
cpsievert 45afeea
Merge branch 'main' into feat/current_output_id
cpsievert 25f81f3
Move context manager from `AsyncValueFn`'s call to `Outputs`'s call
schloerke e472bb2
Move renderer context manager into clientdata where it is used
schloerke 5040860
Update _session.py
schloerke 464394d
Add and test for module support within client data
schloerke a1a0962
changle and clean up app
schloerke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from shiny import App, Inputs, Outputs, Session, render, ui | ||
|
||
app_ui = ui.page_fluid( | ||
ui.input_dark_mode(mode="light", id="dark_mode"), | ||
ui.output_text("text1"), | ||
ui.output_text("text2"), | ||
ui.output_text("info").add_class("shiny-report-theme"), | ||
) | ||
|
||
|
||
def server(input: Inputs, output: Outputs, session: Session): | ||
|
||
@render.text | ||
def text1(): | ||
id = session.current_output_id() or "None" | ||
return f"Output ID: {id}" | ||
|
||
@output(id="text2") | ||
@render.text | ||
def _(): | ||
id = session.current_output_id() or "None" | ||
return f"Output ID: {id}" | ||
|
||
@render.text | ||
def info(): | ||
bg_color = session.clientdata.output_bg_color() | ||
return f"BG color: {bg_color}" | ||
|
||
|
||
app = App(app_ui, server) |
29 changes: 29 additions & 0 deletions
29
tests/playwright/shiny/session/current_output_info/test_current_output_info.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from playwright.sync_api import Page | ||
|
||
from shiny.playwright import controller | ||
from shiny.run import ShinyAppProc | ||
|
||
|
||
def test_current_output_info(page: Page, local_app: ShinyAppProc) -> None: | ||
|
||
page.goto(local_app.url) | ||
|
||
# Check that the output ID is displayed correctly in the UI | ||
text1 = controller.OutputText(page, "text1") | ||
text2 = controller.OutputText(page, "text2") | ||
|
||
text1.expect_value("Output ID: text1") | ||
text2.expect_value("Output ID: text2") | ||
|
||
# Check that we can get background color from clientdata | ||
info = controller.OutputText(page, "info") | ||
info.expect_value("BG color: rgb(255, 255, 255)") | ||
|
||
# Click the dark mode button to change the background color | ||
dark_mode = controller.InputDarkMode(page, "dark_mode") | ||
dark_mode.expect_mode("light") | ||
dark_mode.click() | ||
dark_mode.expect_mode("dark") | ||
|
||
# Check that the background color has changed | ||
info.expect_value("BG color: rgb(29, 31, 33)") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.