Repository navigation
Conversation
The old example handed the model a pre-digested summary (count, mean,
top continents) of a lasso selection, which it just paraphrased back --
a @render.text could have shown the same thing. The new version hands
the model the selected countries themselves and asks a question only
world knowledge can answer ("why are these below the trend curve?"),
switching from manual @chat.on_user_submit + stream_async to the
Chat(client=...) + register_tool pattern examples 3 and 4 already use.
Also documents, in one place, that a chat's tool calls run inside a
reactive.extended_task and therefore require reactive.isolate() to read
an accessor at all (confirmed empirically: omitting it raises
"not allowed to read reactive sources from inside a Extended Task").
Pointed at the now-removed @chat.on_user_submit example; the worked example it refers to reads a lasso selection from a registered tool instead.
The doc said isolate() just avoided creating a reactive dependency; it's actually required to avoid a RuntimeError, since the tool runs inside shinychat's reactive.extended_task. Points at the ai-exploration guide's Pitfalls section instead of re-explaining the mechanism here.
✅ Deploy Preview for shinywidgets canceled.
|
Example 2 only ever reads plot.selected_rows(df), never plot.selected() directly, so follow #520's convention and declare the opt-in with the name actually called.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The guide still incorrectly attributes reactive feedback loops to client tool calls and claims an extra websocket round trip for selection state already stored on the server.
2 open issues
What changed in this PR
Updates the AI exploration guide to demonstrate how an LLM adds world knowledge to selected widget data.
Changes:
- Replaces manual chat handling with a registered selection tool and automatic streaming.
- Uses selected country rows and a logarithmic GDP axis for the worked example.
- Revises reactive-isolation guidance and related cross-references.
| File | Description |
|---|---|
| website/guide/reacting-to-widgets/index.md | Updates the chat example cross-reference. |
| website/guide/ai-exploration/index.md | Reworks the selection example and tool guidance. |
| website/guide/ai-exploration/examples/02_selection_to_chat_context.py | Implements tool-based selection context. |
| website/gallery/showcases/map-chart-chat/index.md | Clarifies why tool reads require isolation. |
Review effort: Balanced
- Reactive loops: tool reads are isolated and tools only run when the model calls them, so a tool cannot self-subscribe into a feedback loop; attribute that hazard to reactive effects, where it applies. - Latency: the widget syncs the lasso to the server as it is drawn, so get_selection() reads server-side state; drop the incorrect extra websocket round-trip claim.
This branch was previously deployed
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.

Chat examples should show an LLM doing something a plain output can't. Example 2 in the AI exploration guide ("A widget's selection becomes chat context") handed the model a pre-computed count, mean, and top continents for a lasso selection; the model just restated those numbers, which a
@render.textcould already show.It now hands the model the selected countries themselves and asks something only world knowledge can answer: lasso the countries well below the trend (Botswana, Equatorial Guinea, Gabon, South Africa) and ask "Why are these below the curve?" The answer covers HIV/AIDS, resource income that doesn't reach most people, and inequality, none of which is in the data. It also uses the modern
Chat(id, client=...)+register_tool()pattern instead of@chat.on_user_submit+stream_async+append_message_stream, matching examples 3 and 4 on the same page.What changed
ai-exploration/examples/02_selection_to_chat_context.pyand its code block: newget_selection()tool and question, re-shot screenshots, and the real model answer quoted.Chat(id, client=...)"only works when the model's reply doesn't need anything beyond the user's literal text"; examples 3 and 4 and the loan-chat showcase already disprove it.reacting-to-widgets/index.md: fixed a cross-reference that pointed at the removedon_user_submithandler.gallery/showcases/map-chart-chat/index.md: corrected the stated reasonsummarize_viewwraps its read inreactive.isolate().reactive.isolate()in toolsA chat's tool calls run inside the
reactive.extended_taskshinychat streams the reply in, and an extended task raisesRuntimeError: You're not allowed to read reactive sources from inside a Extended Taskon any reactive read. So a tool that reads an accessor must wrap the read inreactive.isolate(); a write-only tool (fly_to) doesn't need it. This is now explained once, in the guide's Pitfalls, with a short pointer at each site. A shinychat-side change that would make this unnecessary is being looked into separately.Uses
listen_to=["selected_rows"], so merge after #520.