-
Notifications
You must be signed in to change notification settings - Fork 108
Add session.clientdata
; allow access to input names via dir()
#1832
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
clientdata
accessor to session
clientdata
accessor to session
; allow access to input names via dir()
def clientdatatext(): | ||
cdata = session.clientdata | ||
return "\n".join([f"{name} = {cdata[name]()}" for name in reversed(dir(cdata))]) |
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.
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"
pass
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.
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
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Could you test url_search
, url_hash_initial
and url_hash
here? Those are all more valuable and likely to be used than, say, url_protocol
.
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.
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
clientdata
accessor to session
; allow access to input names via dir()
session.clientdata
; allow access to input names via dir()
@gadenbuie this is ready for another look -- thanks for the suggestions! |
Closes #623
Closes #711
Here's an example to replicate the one on this page https://shiny.posit.co/r/articles/build/client-data/
app.py
TODO
How to best document? Translate https://shiny.posit.co/r/articles/build/client-data/ to Python?