Draft
Conversation
Port of the Python ggsql visualization feature (#201) to the R package. Adds an opt-in `visualize` tool that enables LLM-generated data visualizations via ggsql. When enabled, the LLM writes ggsql queries (SQL + VISUALISE clause) that are executed and rendered as interactive charts inline in the chat using ggsql's native Shiny bindings.
cd14057 to
5731d0a
Compare
Replace shiny-workflows reusable workflows with a custom workflow that installs ggsql's build prerequisites (Node.js, tree-sitter-cli, ODBC) before R dependency installation. The previous workflow failed because pak couldn't build ggsql from source without tree-sitter-cli.
cpsievert
commented
Apr 29, 2026
Comment on lines
+73
to
+77
| if (has_keyword) { | ||
| rlang::abort( | ||
| "VISUALISE clause was not recognized. VISUALISE and MAPPING accept column names only — no SQL expressions, CAST(), or functions. Move all data transformations to the SELECT clause, then reference the resulting column by name in VISUALISE." | ||
| ) | ||
| } |
Contributor
Author
There was a problem hiding this comment.
This may not be necessary anymore posit-dev/ggsql#389
cpsievert
commented
Apr 29, 2026
Comment on lines
+533
to
+545
| 5. **Column casing in VISUALISE**: DuckDB lowercases unquoted column names in query results, and VISUALISE validates column references **case-sensitively**. If your source table has uppercase column names (e.g., from Snowflake), you **must** alias them to lowercase in the SELECT clause: | ||
| ```sql | ||
| -- WRONG: VISUALISE references uppercase name, but DuckDB lowercases it in results | ||
| SELECT ROOM_TYPE, COUNT(*) AS listings FROM airbnb | ||
| VISUALISE ROOM_TYPE AS x, listings AS y | ||
| DRAW bar | ||
|
|
||
| -- CORRECT: Alias to lowercase, then reference the alias | ||
| SELECT ROOM_TYPE AS room_type, COUNT(*) AS listings FROM airbnb | ||
| VISUALISE room_type AS x, listings AS y | ||
| DRAW bar | ||
| ``` | ||
| As a general rule, always use lowercase column names and aliases in both SELECT and VISUALISE clauses. |
Contributor
Author
There was a problem hiding this comment.
May not be necessary after posit-dev/ggsql#374
This reverts commit 4490950.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
R port of #201. Adds an opt-in
visualizetool to querychat's R package, enabling LLM-generated data visualizations via ggsql. When enabled, the LLM can write ggsql queries (SQL +VISUALISEclause) that are executed and rendered as interactive charts inline in the chat.Usage
Install
Example app
The
visualizetool is opt-in — include"visualize"in thetoolsvector alongside"query"and/or"update"to enable it.What it looks like
Charts render inline in the chat with a collapsible footer showing the ggsql query (with syntax highlighting), a copy button, and save options:
Key changes
visualizetool (opt-in viatools = c("query", "visualize")): The LLM writes a full ggsql query, which is executed against the data source and rendered using ggsql's native Shiny bindings (ggsql::renderGgsql/ggsql::ggsqlOutput).querychat_viz.R): Uses DataSource for SQL execution (preserving database pushdown), then feeds results into ggsql's DuckDB reader for VISUALISE processing.V8+rsvg) and sent back to the LLM so it can see what it produced.collapsedparameter onquerychat_query: Preparatory queries (e.g., inspecting data before visualizing) can start collapsed so the chart remains the focal point.Test plan
execute_ggsql,extract_visualise_table,has_layer_level_sourcetool_visualize_dashboard(creation, callback, error handling)truncate_errorcollapsedparameter on query tool