fix: Expose id in ui/server methods to support Shiny for R modules and multiple instances#172
fix: Expose id in ui/server methods to support Shiny for R modules and multiple instances#172
id in ui/server methods to support Shiny for R modules and multiple instances#172Conversation
1744be8 to
c9206b7
Compare
gadenbuie
left a comment
There was a problem hiding this comment.
I liked considering the idea of passing in ns() (it's a creative solution!), but it feels little off compared to the established patterns we use with Shiny modules.
In #173 I'm proposing that we expose id directly, while still allowing for the server-side rendered case to "just work". More than just solving the Shiny modules use case, that opens up re-using a qc object for more than chat instance.
…173) * refactor: Allow directly providing `id` * chore: Also `$sidebar()` and update docstrings
|
@gadenbuie mind updating the description and taking this over the finish line? |
|
@cpsievert I updated the PR description, made the |
id in ui/server methods to support Shiny for R modules and multiple instances
|
Thanks! LGTM other than the one suggestion. |
Co-authored-by: Carson Sievert <cpsievert1@gmail.com>
Closes #169
This PR introduces proper support for using QueryChat within Shiny (for R) modules by allowing explicit
idparameter overrides in$ui(),$sidebar(), and$server()methods.Key Changes
1. Added
idparameter to$ui(),$sidebar(), and$server()methods:idwhen calling these methodsid = ns("your_id")2. Follows idiomatic Shiny module patterns:
ns()in the UI function3. Enables multiple instances from the same QueryChat object:
idoverride, users can create multiple chat interfaces from a single QueryChat instanceImplementation Details
$ui()and$sidebar()to accept an optionalidparameter instead ofnsfunction$server()to accept an optionalidparameteridis not provided, falls back toself$idwith automatic namespace detection (vianamespaced_id()) for UI methodsiddirectlyUsage
In a Shiny module UI function:
In a Shiny module server function:
In a regular Shiny app (no module):