Skip to content

Conversation

@cpsievert
Copy link
Contributor

@cpsievert cpsievert commented Dec 16, 2025

Closes #169

This PR introduces proper namespace handling for QueryChat within Shiny (for R) modules:

Changes to $ui() and $sidebar() methods:

  1. Added ns parameter: Users can now explicitly pass a Shiny namespacing function (shiny::NS()) when calling these methods within a module UI function
  2. Automatic namespace detection: When called in a module server context (e.g., with renderUI()), the namespace is automatically inferred from the session
  3. Error handling: Added validation to prevent users from incorrectly passing id directly, with helpful error messages guiding them to use ns instead

Implementation details:

  • New namespaced_id() helper function that checks for a reactive domain and applies namespacing when available
  • Updated documentation for the id field to clarify it's an instance ID rather than specifically a module ID
  • Proper parameter documentation for the new ns argument

Usage

When using QueryChat in a module UI function, pass the namespacing function:

test_module_ui <- function(id) {
  ns <- NS(id)
  qc$ui(ns = ns)
}

When using renderUI() in a module server, the namespacing is automatic:

output$querychat_sidebar <- renderUI({
  qc$ui()  # Namespace inferred automatically
})

This comment was marked as resolved.

@cpsievert cpsievert marked this pull request as ready for review December 16, 2025 23:42
@cpsievert cpsievert requested a review from gadenbuie December 16, 2025 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to run QueryChat inside shinyModule

2 participants