Skip to content

Give the Plots pane image alt text and announce plot changes - #19342

Merged
gtritchie merged 18 commits into
mainfrom
bugfix/plot-alt-text
Oct 29, 2026
Merged

gtritchie merged 18 commits into
mainfrom
bugfix/plot-alt-text

Conversation

@gtritchie

Copy link
Copy Markdown
Member

Fixes #19337.

The plot image in the Plots pane now has alt text with its position in the plot history, followed by the alt text the plot's author supplied, if any:

  • Plot 2 of 5
  • Plot 3 of 5: Weight falls as fuel economy rises (from ggplot2's labs(alt = ...))

Screen readers also announce this text through the polite status live region when a new plot is drawn or the history moves to another plot. Redraws of the same plot (resize, refresh, client reconnect) are not announced. The announcement is a new plot_changed entry in AriaLiveService, so it can be turned off in Global Options > Accessibility ("New or selected plot").

How the author's alt text is found

ggplot2 (and any other grid code) attaches it as an alt-label attribute on the grob it draws. Grid records each top-level grob it draws in the device's engine display list, so .rs.graphicsAltText() reads the attribute from there. The engine display list is reset on every new page. Grid's own display list is not: a base-graphics plot drawn after a ggplot would otherwise inherit the ggplot's alt text.

Each Plot reads its alt text when its image is rendered from the display, and keeps it for cached redraws. A plot restored from a previous session reads it on first display. A failed read is logged and retried on the next render.

How plot changes are detected

PlotManager sets activePlotChanged when a new page starts or the active plot changes, and clears it when the state is sent to the client. PlotsTab announces when that flag is set, or when the alt text of the plot on show changes. The second case covers a ggplot shown while still blank, because ggplot2 starts the page before its build finishes. The announcement lives in PlotsTab rather than the lazily loaded presenter, which only sees the last state sent before it loads.

Cost

The alt text read is an R loop over the page's display list. It runs only when a plot's snapshot is taken, which is already a much heavier step. With 100,000 points() calls on one page, the read took 68 ms against 1,080 ms for the snapshot save. A ggplot is a single display-list entry regardless of its size.

Tests

  • src/cpp/tests/testthat/test-graphics.R: alt text is found, combined across grobs, trimmed, not carried to a later page, kept through snapshot save and restore, and read from ggplot2; display-list entries with a failing [[ method are skipped.
  • e2e/rstudio/tests/panes/plots/plot_alt_text.test.ts: alt text and announcements for a ggplot, a later base plot, history navigation, alt text drawn after the plot is shown, no announcement on refresh, and no announcement when the preference turns it off.

Follow-ups: #19339 (combined plots), #19340 (Zoom window, export previews, notebook plots), #19341 (unused PlotsPane.refresh()).

Collect the alt text authors attach to drawn grobs (e.g. ggplot2's
labs(alt = ...)) from the RStudio device's engine display list, which is
reset on every new page, and send it with the plots state. Also flag
when a different plot is shown, as opposed to the same plot redrawn
after a resize, so the client can announce new plots.

Addresses #19337
The image gets alt text with its position in the plot history, followed
by the author's alt text when there is one. The same text is announced
through a new, user-configurable plot_changed live announcement when a
new plot is drawn or the history moves to another plot.

Addresses #19337
The Plots presenter is loaded lazily. Until it loads, PlotsTab keeps
only the latest plots state for it, so a state flagging a new plot could
be replaced by one without the flag before the presenter saw it, and
the plot went unannounced. PlotsTab sees every state, so announce there.

Addresses #19337
A display list entry's arguments can be any object, and one whose own
[[ method fails dropped the page's alt text and logged an error on
every render.

Addresses #19337
Alt text was read from the device's display on every render, including
renders that reuse a plot's cached image. That repeated an R loop over
the whole display list on each resize, and showed another plot's alt
text when restoring a plot from history failed. Each plot now reads it
when its image is taken, or on first display after a session restore,
inside the scope that holds off polled events.

Addresses #19337
ggplot2 starts a new page before building the plot, so a slow build can
be shown, and its plot change announced, while the page is still blank.
Announce the alt text again when it changes for the plot on show.

Addresses #19337
A failed read was stored as empty alt text, so the plot kept no alt
text until it was next redrawn. It is now left unread, and the next
render reads it again.

Addresses #19337
Whitespace-only alt text gave a description with nothing after the
colon, e.g. "Plot 1 of 1:  ".

Addresses #19337
Info bars and other widgets have status regions too, and watching one
of those would let the tests that expect no announcement pass without
checking anything.

Addresses #19337
@gtritchie gtritchie added this to the 2026.11 (Montauk Daisy) milestone Oct 29, 2026
@github-actions

Copy link
Copy Markdown

RStudio E2E - all platforms

All tests passed!

#################### 100% pass rate

Passed Failed Skipped Flaky
4614 0 239 2
Platform ✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
✅ auth-teardown 4 0 16 0
✅ desktop-linux 1147 0 52 1
✅ desktop-macos 1163 0 38 0
✅ desktop-windows 1156 0 50 0
✅ server-linux 1096 0 51 1
✅ setup 48 0 32 0
View / download the full report

View report online -- opens in the browser, no download needed. Available for 14 days.

Download playwright-report.zip -- extract and open index.html

Includes screenshots, traces, and step-by-step details for every test. Expires in 15 days.


All platforms - commit 4b78f65787492483bddd745aaad4ac1a436d6d0d - Run #1808

@gtritchie
gtritchie merged commit 6d66676 into main Oct 29, 2026
45 checks passed
@gtritchie
gtritchie deleted the bugfix/plot-alt-text branch October 29, 2026 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Plot image in the Plots pane has no alt text

1 participant