Skip to content

Make render_plotly's brushing() opt-in - #508

Merged
cpsievert merged 1 commit into
fix/plotly-late-callbacksfrom
fix/plotly-brushing-opt-in
Nov 30, 2026
Merged

cpsievert merged 1 commit into
fix/plotly-late-callbacksfrom
fix/plotly-brushing-opt-in

Conversation

@cpsievert

@cpsievert cpsievert commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #511; merge that first. The diff here shows only this PR's changes.

brushing() is the one streaming plotly accessor that's still always-on. Unlike selecting() and hover(), which already require listen_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:

before (opt-out, current main) after (opt-in)
box-select drag 16 frames, 14.1 KB 4 frames, 9.2 KB
lasso drag 29 frames, 30.7 KB 4 frames, 11.3 KB

(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's AccessorSpec in shinywidgets/_plotly.py now sets opt_in=True, so reading brushing() requires listen_to=["brushing"], matching selecting() and hover(). 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 the plotly_accessors Playwright test, which already drags while reading brushing().

Updated every place that reads plot.brushing() to pass listen_to=["brushing"]: the plotly_accessors Playwright app, the plotly widget guide's brushed()/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 list brushing() 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-types
  • uv run pytest tests/playwright/plotly_accessors/ tests/playwright/plotly_selection_seed/ tests/playwright/plotly_region_only/

@netlify

netlify Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for shinywidgets canceled.

Name Link
🔨 Latest commit 71606cd
🔍 Latest deploy log https://app.netlify.com/projects/shinywidgets/deploys/6b0dbb4054642a884f101cb0

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

@github-actions
github-actions Bot temporarily deployed to pull request November 23, 2026 23:16 Inactive
@cpsievert
cpsievert force-pushed the fix/plotly-brushing-opt-in branch from f587b24 to 783d6b1 Compare November 23, 2026 23:22
@cpsievert
cpsievert changed the base branch from main to fix/plotly-late-callbacks November 23, 2026 23:22
@cpsievert
cpsievert requested a balanced review from Copilot November 23, 2026 23:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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

@github-actions
github-actions Bot temporarily deployed to pull request November 23, 2026 23:26 Inactive
@cpsievert
cpsievert force-pushed the fix/plotly-brushing-opt-in branch from 783d6b1 to 3d92288 Compare November 23, 2026 23:30
@cpsievert
cpsievert added this pull request to stack #513 November 30, 2026 16:52
@github-actions
github-actions Bot temporarily deployed to pull request November 30, 2026 16:55 Inactive
@github-actions
github-actions Bot temporarily deployed to pull request November 30, 2026 17:21 Inactive
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
cpsievert force-pushed the fix/plotly-brushing-opt-in branch from 67b1656 to 71606cd Compare November 30, 2026 18:06
@cpsievert
cpsievert marked this pull request as ready for review November 30, 2026 18:07
@github-actions
github-actions Bot temporarily deployed to pull request November 30, 2026 18:10 Inactive
@cpsievert
cpsievert merged commit ec0e937 into main Nov 30, 2026
30 of 31 checks passed

This branch was previously deployed

1 inactive deployment
pull request — 71606cd4 Deployed Nov 30, 2026 by github-actions[bot]
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.

2 participants