Repository navigation
Make render_plotly's brushing() opt-in - #508
Merged
Merged
Conversation
✅ Deploy Preview for shinywidgets canceled.
|
cpsievert
force-pushed
the
fix/plotly-brushing-opt-in
branch
from
November 23, 2026 23:22
f587b24 to
783d6b1
Compare
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block approval of the live-brushing opt-in change.
No open issues 🎉
What changed in this PR
Makes render_plotly.brushing() opt-in to avoid unnecessary client-to-server traffic during selection drags. Apps that use live brushing must declare listen_to=["brushing"]; completed selections through brushed() remain always-on.
Changes:
- Gates live brushing through the existing accessor opt-in mechanism, without JavaScript changes.
- Adds opt-in regression tests and updates browser fixtures and runnable examples.
- Aligns website guidance, API docstrings, the bundled skill reference, and the changelog.
| File | Description |
|---|---|
website/widgets/plotly/index.md |
Documents brushing opt-in and updates the example. |
website/widgets/plotly/examples/08_brushed.py |
Explicitly enables live brushing. |
website/guide/linked-views/index.md |
Enables brushing in both histogram examples. |
website/guide/linked-views/examples/18_datashader_brush_summaries.py |
Adds matching opt-ins to the standalone example. |
tests/unit/test_plotly_accessors.py |
Covers default non-binding, opt-in enforcement, and enabled updates. |
tests/playwright/plotly_accessors/app.py |
Enables brushing for the existing browser test. |
shinywidgets/.agents/skills/shinywidgets/references/widgets/plotly.md |
Lists brushing among opt-in accessors. |
shinywidgets/_render_widget.py |
Updates renderer and brushing method docstrings. |
shinywidgets/_plotly.py |
Sets BRUSHING to opt_in=True. |
CHANGELOG.md |
Includes brushing in the opt-in accessor summary. |
Review effort: Balanced
cpsievert
force-pushed
the
fix/plotly-brushing-opt-in
branch
from
November 23, 2026 23:30
783d6b1 to
3d92288
Compare
brushing() streamed the drag region on every mouse move of a box or lasso selection, even for apps that never read it, unlike the other streaming accessors (selecting(), hover()) which already require listen_to. Each frame also costs a server reactive flush and an ack. Since this hasn't shipped yet, fix it now rather than after release, when flipping an accessor to opt-in would be a breaking change.
cpsievert
force-pushed
the
fix/plotly-brushing-opt-in
branch
from
November 30, 2026 18:06
67b1656 to
71606cd
Compare
cpsievert
marked this pull request as ready for review
November 30, 2026 18:07
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.
brushing()is the one streaming plotly accessor that's still always-on. Unlikeselecting()andhover(), which already requirelisten_to=[...],brushing()attaches at render time regardless of whether an app reads it, so every box or lasso drag forwards the selection region to the server on every mouse move -- one reactive flush and ack per frame -- even for apps that never call.brushing().This hasn't shipped yet, so it's cheap to fix now and expensive later: turning an always-on accessor into opt-in after release is a breaking change, the reverse isn't. Worth deciding before the next release.
Measured in Chromium, client->server websocket traffic for one drag on an app that reads no accessors:
(Numbers above are from a fresh measurement on this branch's base vs. this change, in the same environment; they land in the same ballpark as the 0.8.2-vs-main numbers that motivated this, with some run-to-run variance from mouse-event timing.)
Change
BRUSHING'sAccessorSpecinshinywidgets/_plotly.pynow setsopt_in=True, so readingbrushing()requireslisten_to=["brushing"], matchingselecting()andhover().brushed()(the region once the gesture ends, one small message per gesture) is untouched and stays always-on.No JS changes: the browser bridge only binds events Python asks for, so gating
brushing()server-side was enough -- confirmed with the unit tests and theplotly_accessorsPlaywright test, which already drags while readingbrushing().Updated every place that reads
plot.brushing()to passlisten_to=["brushing"]: theplotly_accessorsPlaywright app, the plotly widget guide'sbrushed()/brushing()example, and the linked-views guide's large-data brushing example (and its standalone example file). Docs (widget page, docstrings, bundled skill reference) and the CHANGELOG's accessor summary now listbrushing()among the opt-in accessors.Test plan
uv run pytest tests/unit/test_plotly_accessors.py tests/unit/test_accessors.py tests/unit/test_agent_skill.py(new tests cover:brushing_is_not_bound_without_opting_in,brushing_updates_during_a_drag_when_listened_to,brushing_is_opt_in)uv run python website/_tools/check_docs.py(reports nothing)make check-format/make check-typesuv run pytest tests/playwright/plotly_accessors/ tests/playwright/plotly_selection_seed/ tests/playwright/plotly_region_only/