fix(pkg-r): Directly expose id rather than ask for ns() function
#173
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.
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.