Skip to content

Conversation

@cpsievert
Copy link
Contributor

Closes #107

This PR adds Shiny bookmarking support to the R package's QueryChat class, bringing it to feature parity with the Python implementation added in #104.

Behavior

When bookmarking is enabled, the following state is preserved across sessions:

  • Chat history - Full conversation with the LLM (via shinychat::chat_restore())
  • Current SQL query - The active query filtering the data
  • Query title - The LLM-generated title for the current query
  • Greeting state - Whether the welcome message has been shown (prevents duplicates on restore)

Note

This does raise some questions related to #113 in terms of managing greeting/chat state. I think it'd be better to leave that for a follow up PR where we can address both R and Python at once.

Changes

  • mod_server() function - Added enable_bookmarking parameter (default: FALSE)

    • Integrated shinychat::chat_restore() to save/restore chat history
    • Added shiny::onBookmark() handler to save current query, title, and greeting state
    • Added shiny::onRestore() handler to restore saved state
    • Wrapped greeting logic in a reactive observer to prevent duplicate greetings on restore
  • QueryChat$server() method - Added enable_bookmarking parameter (default: FALSE)

    • Users can explicitly enable bookmarking in custom apps
    • Passes parameter through to mod_server()
  • QueryChat$app_obj() method - Automatically enables bookmarking when appropriate

    • When bookmark_store = "url" (default) or "server", bookmarking is automatically enabled
    • No user action required beyond setting bookmark_store

Usage

Using querychat_app() (automatic)

# Bookmarking enabled by default with URL bookmarking
querychat_app(mtcars, "mtcars")

# Explicitly set bookmark_store
querychat_app(mtcars, "mtcars", bookmark_store = "server")

# Disable bookmarking
querychat_app(mtcars, "mtcars", bookmark_store = "disable")

Using QueryChat$server() in custom apps

qc <- QueryChat$new(mtcars, "mtcars")

ui <- function(request) {
  page_sidebar(
    qc$sidebar(),
    verbatimTextOutput("sql")
  )
}

server <- function(input, output, session) {
  # Explicitly enable bookmarking
  qc_vals <- qc$server(enable_bookmarking = TRUE)

  output$sql <- renderText(qc_vals$sql())
}

shinyApp(ui, server, enableBookmarking = "url")

@cpsievert cpsievert marked this pull request as ready for review December 2, 2025 15:58

This comment was marked as resolved.

@cpsievert
Copy link
Contributor Author

I'm gonna merge this now since this will get R updated with Python and also help unblock #113.

@gadenbuie if you notice anything we should change or improve upon here, I'm happy to address in a follow up.

@cpsievert cpsievert merged commit 7e47ebf into main Dec 2, 2025
@cpsievert cpsievert deleted the feat/r-enable-bookmark branch December 2, 2025 21:51
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.

(R) Add bookmarking support to querychat_app()/querychat_server()

2 participants