-
Couldn't load subscription status.
- Fork 115
Add session.clientdata; allow access to input names via dir()
#1832
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
Changes from 7 commits
46ee863
c248afe
4d22cb4
c41e609
ea07a84
42b08e1
2ade16e
a30b8c8
1547687
e1e4526
ec74610
8cf3f31
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,21 @@ | ||||||||||||||||||
| # pyright: reportUnknownMemberType=false, reportUnknownVariableType=false | ||||||||||||||||||
| import matplotlib.pyplot as plt | ||||||||||||||||||
| import numpy as np | ||||||||||||||||||
|
|
||||||||||||||||||
| from shiny.express import input, render, session, ui | ||||||||||||||||||
|
|
||||||||||||||||||
| with ui.sidebar(open="closed"): | ||||||||||||||||||
| ui.input_slider("obs", "Number of observations:", min=0, max=1000, value=500) | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| @render.code | ||||||||||||||||||
| def clientdatatext(): | ||||||||||||||||||
| cdata = session.clientdata | ||||||||||||||||||
| return "\n".join([f"{name} = {cdata[name]()}" for name in reversed(dir(cdata))]) | ||||||||||||||||||
|
||||||||||||||||||
| def clientdatatext(): | |
| cdata = session.clientdata | |
| return "\n".join([f"{name} = {cdata[name]()}" for name in reversed(dir(cdata))]) | |
| def client_data_text(): | |
| client_data = session.clientdata | |
| return "\n".join([ | |
| f"{name} = {client_data[name]()}" for name in reversed(dir(client_data)) | |
| ]) |
To avoid CDATA vibes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't get autocomplete for session.clientdata, right? So you can use dir() to find out the methods but you won't get autocomplete for session.clientdata.url_*(). The autocomplete would be helpful but isn't a blocker.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, no autocomplete. And agreed, it'd be useful, but I also don't see a low effort way to faithfully type those values (not to mention them easily getting out of sync when shiny.js changes).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess maybe it'd be worth having a ClientData class though so we can at least make them discoverable through the API reference?
class ClientData(Inputs):
"TODO: docs here"
passThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, hold on, maybe there is a sensible thing to do for autocomplete as well...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I also don't think all the values need to be accessible in autocomplete, but it'd be useful to have the url_ and other stable data as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the nudge here -- e1e4526 takes a more typing and documentation friendly approach
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import re | ||
|
|
||
| from playwright.sync_api import Page | ||
|
|
||
| from shiny.playwright import controller | ||
| from shiny.run import ShinyAppProc | ||
|
|
||
|
|
||
| def test_output_image_kitchen(page: Page, local_app: ShinyAppProc) -> None: | ||
|
|
||
| page.goto(local_app.url) | ||
|
|
||
| text = controller.OutputTextVerbatim(page, "clientdatatext") | ||
|
|
||
| # This doesn't cover all the clientdata values since some of them | ||
| # are environment-dependent. However, this at least checks that the | ||
| # clientdata object is available and that some values are present. | ||
| text.expect.to_contain_text("url_protocol = http") | ||
| text.expect.to_contain_text("url_pathname = /") | ||
| text.expect.to_contain_text( | ||
| re.compile("url_hostname = (localhost|127\\.0\\.0\\.1)") | ||
| ) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you test There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a shinycoreci app that already does a good job of covering the front end logic (see comment added in a30b8c8), so I'd rather not redo it |
||
| text.expect.to_contain_text("output_myplot_hidden = False") | ||
| text.expect.to_contain_text("output_myplot_bg = rgb(255, 255, 255)") | ||
| text.expect.to_contain_text("output_clientdatatext_hidden = False") | ||
Uh oh!
There was an error while loading. Please reload this page.