-
Notifications
You must be signed in to change notification settings - Fork 22
fix(pkg-r): Directly expose id rather than ask for ns() function
#173
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
Conversation
I feel a bit torn on how true this is. It is idiomatic if you know that
The class based approach is already non-standard, so I'm not sure following standards is obviously more helpful, especially when the standard is rooted in semi-internal implementation details Ultimately, I do feel a bit conflicted on this. I do agree in part with stance, but the aspect that pushed me towards |
It's idiomatic in a few ways, most notably that in Shiny modules anywhere that you would ordinarily give an It's also idiomatic in the sense that we literally outline this exact scenario in our modules article, succinctly enough that I can quote it entirely here
We have enough examples of this already where you can set a value in the constructor that can later be overridden in specific methods. It's less "override into irrelevance" and more "convenience by default". The approach in this PR benefits two use cases:
The first use case is covered by both PRs, but the second case is much trickier to set up correctly if you can't access |
…and multiple instances (#172) * fix(pkg-r): better support for modules. Closes #169 * `air format` (GitHub Actions) * fix(pkg-r): Directly expose `id` rather than ask for `ns()` function (#173) * refactor: Allow directly providing `id` * chore: Also `$sidebar()` and update docstrings * chore(pkg-r): Add example app with a module * feat: Prepend "querychat_" to automatic `id` * feat(pkg-py): Expose `id` in `.ui`, `.sidebar` and `.server` methods * chore: Add NEWS/CHANGELOG items * Update pkg-py/CHANGELOG.md Co-authored-by: Carson Sievert <cpsievert1@gmail.com> --------- Co-authored-by: cpsievert <cpsievert@users.noreply.github.com> Co-authored-by: Garrick Aden-Buie <garrick@adenbuie.com>
This stacks on #172 and is an alternate approach that exposes
id.The
nsargument in #172 is convenient, but it's also not a standard a pattern that we use in Shiny modules. In general, it's normal to expect that you'll need to wrap anyidfor any component inns(), e.g.id = ns("component"), in a Shiny module, including when you're nesting Shiny modules.Passing in
nsis an interesting idea, but it's not the standard established pattern and I'm not sure it's entirely worth it because it doesn't entire enable another class of use cases.Allowing users to pass in
id, on the other hand, is idiomatic and expected and gives users extra flexibility to call$ui()and$server()with alternate IDs, even in a non-module use case. That's entirely valid because we've decoupled the$server()return values from the parent QueryChat class.Example
Here's the example in #172 updated to use the new pattern.
So while the new R6 class saves you from needing to pass IDs around when you're using
qc$ui()andqc$server()in a normal Shiny app (and you only have one), if you're in Shiny modules or if you have more than one chat from the sameqcsource object, you'll be able to connect theids by passing them explicitly.