Reacting to widgets
When someone clicks a point, lassos a selection, or pans a map, you want that gesture in your app as easily as you’d read a slider. A reactive accessor does that: it’s a method on a rendered widget that behaves like a Shiny input. plot.clicked() reads like input.my_slider() – call it in a reactive context and it invalidates whatever reads it the moment the user clicks.
Every widget that reports interaction has a handful of these: plot.clicked(), chart.selected_rows(), map.view_state(), tbl.selected(), grid.edited_cell(). They all behave the same way underneath: what they report before the first interaction, what a re-render keeps or resets, and how safe they are to read later, from a button or a chat handler. This article is where those shared rules live; each per-widget guide documents its own accessors in detail, and the companion cheat sheet lists every accessor on every renderer.
The mental model: accessors are inputs that remember
Every accessor follows the same rules, regardless of which widget or gesture it reports:
- it attaches the moment its output renders, not on its first read;
- it records the interaction whether or not anything has read it yet – a click, a lasso, a drag;
- it keeps or re-seeds its value across a re-render, depending on what it reports (next two sections).
A few accessors are opt-in, because their payload can grow without bound or stream continuously – plotly’s selected()/selecting()/brushing()/hover() (and selected_rows(), which reads selected()), kepler.gl’s config(), and nglview’s camera_orientation(). Declare one with listen_to, naming the method you’ll call: @render_plotly(listen_to=["selected_rows"]) turns on plot.selected_rows(). Reading an undeclared opt-in accessor raises, pointing at listen_to. Each per-widget guide flags which of its accessors are opt-in.
examples/01_mental_model.py compares an accessor to the lower-level primitive underneath it, reactive_read().
# Accessors read like inputs. This renders the same ipyleaflet map twice,
# side by side: the left card reads `map.zoom()` and `map.center()` -- the
# renderer's accessors -- and the right card reads the identical state with
# the lower-level primitive underneath them, `reactive_read(map.widget, "zoom")`.
# Both update together on every pan or zoom; the accessor adds nothing here but
# a name, a docstring, and (for other accessors) a default rate policy -- see
# the next examples for cases where that default actually matters.
from ipyleaflet import Map
from shiny.express import render, ui
from shinywidgets import reactive_read, render_ipyleaflet
ui.page_opts(title="Accessors vs. reactive_read", fillable=True)
with ui.layout_columns():
with ui.card(full_screen=True):
ui.card_header("The map")
@render_ipyleaflet
def map():
return Map(center=(45.5, -122.6), zoom=10)
with ui.card():
ui.card_header("map.zoom() / map.center() -- the accessor")
@render.code
def via_accessor():
return f"zoom={map.zoom()}\ncenter={map.center()}"
with ui.card():
ui.card_header('reactive_read(map.widget, ["zoom", "center"]) -- the primitive')
@render.code
def via_reactive_read():
zoom, center = reactive_read(map.widget, ["zoom", "center"])
return f"zoom={zoom}\ncenter={center}"Pan and zoom the map and both panels update together, with identical values:

For a plain state trait like zoom, the two are nearly equivalent: an accessor is just a named, documented wrapper around reactive_read(). Use the accessor where one exists – reactive_read() (and its friend .read(), covered later) is the fallback for traits that don’t have one.
Before the first interaction
Read an accessor before its output has rendered and it cancels silently, like req(False). Once rendered, every accessor settles into one of four states:
- cancels until the browser reports something – k3d’s
camera()before the scene auto-fits. Noneuntil the first interaction – ipyleaflet’sclicked();req(map.clicked())waits on it.[]/{}until the first interaction, when the return type is naturally a collection – bokeh’sselected().- a seeded value from the start – an untouched altair
selected()is already a real, usable object, not a sentinel.
examples/02_not_rendered_none_state.py shows all four, each on a different widget in one app:
# Four different "before the first interaction" states, across four widgets:
#
# - k3d's camera() CANCELS (like `req(False)`) until the browser reports a
# camera -- the output renders nothing at all, same as a widget that
# hasn't rendered. No `req()` needed; there is nothing to check.
# - ipyleaflet's clicked() returns None until the first click.
# `req(map.clicked())` is the pattern for waiting on it.
# - bokeh's selected() returns `[]` (not None) until the first tap/box
# select -- an empty list either means "nothing selected yet" or "a
# selection that caught nothing"; both read the same way.
# - altair's selected() is seeded the moment the chart renders: it is never
# None or empty-as-a-sentinel -- an untouched selection is itself a real,
# usable (empty) Vega-Lite object. Checking `.value` (or `selected_rows()`,
# which returns an empty frame) is how you tell "untouched" from "selected
# nothing" apart -- no `req()` needed either.
import altair as alt
import numpy as np
import pandas as pd
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure
from ipyleaflet import Map
from k3d import points
from shiny.express import render, ui
from shinywidgets import render_altair, render_bokeh, render_ipyleaflet, render_k3d
df = pd.DataFrame({"x": range(10), "y": [i**2 % 7 for i in range(10)]})
bokeh_source = ColumnDataSource(
data=dict(x=list(range(10)), y=[i**2 % 7 for i in range(10)])
)
ui.page_opts(title="Before the first interaction", fillable=True)
with ui.layout_columns():
with ui.card():
ui.card_header("k3d: camera() -- cancels until ready")
@render_k3d
def plot():
return points(np.random.normal(size=(200, 3)).astype("float32"))
@render.code
def camera_out():
return str([round(v, 1) for v in plot.camera()])
with ui.card():
ui.card_header("ipyleaflet: clicked() -- None until the first click")
@render_ipyleaflet
def map():
return Map(center=(45.5, -122.6), zoom=9)
@render.code
def clicked_out():
pt = map.clicked()
return "None (click the map)" if pt is None else str(pt["coordinates"])
with ui.card():
ui.card_header("bokeh: selected() -- [] until the first selection")
@render_bokeh
def bplot():
p = figure(tools="tap,box_select,reset", title="Tap or box-select points")
p.scatter("x", "y", source=bokeh_source, size=14)
return p
@render.code
def bokeh_out():
return f"selected(): {bplot.selected()}"
with ui.card():
ui.card_header("altair: selected() -- never None")
@render_altair
def chart():
brush = alt.selection_interval(name="brush")
return (
alt.Chart(df)
.mark_point(size=100)
.encode(x="x", y="y")
.add_params(brush)
)
@render.code
def selected_out():
sel = chart.selected("brush")
return f"value={sel.value!r}\nselected_rows: {len(chart.selected_rows('brush'))} row(s)"Before any interaction, three panels already show something; only k3d’s camera is still cancelling:

Interacting with each widget settles all four into their touched state:

Each per-widget guide’s accessor table, and the cheat sheet’s “Before any interaction” column, say which of these four states applies to a given accessor.
Never leave
req(x)as a bare statement inside@render.express.req()returns its argument, andrender.expresstreats every bare top-level expression as UI to display – soreq(map.clicked())on its own line renders the value it was meant to gate (or errors trying to render it). Assign the result instead:clicked = req(map.clicked()).
Across re-renders
A re-render builds a brand new widget. What happens to an accessor’s value when that happens depends on what the accessor reports, not on some global “event vs. state” label:
- User-interaction state (clicks, selections, drags) is kept – the accessor keeps reporting the last interaction until the user acts on the new widget.
- Inherent widget state (viewport, zoom, camera) is re-seeded from the new widget every render, so it always matches what’s on screen.
Either way, a reader only re-runs when the value actually changes – just like an ordinary Shiny input. (Pulse accessors such as plotly’s double_clicked() are the exception: they re-fire on every event; see Re-firing and clearing.) That’s what makes “click -> derive something -> draw it on the same plot” safe: a re-render alone doesn’t re-run a kept accessor’s readers, so the derived value can feed the plot’s own render function without looping.
examples/08_across_rerenders.py puts both on the very same map, so the contrast is visible in one screenshot: clicked() is kept, zoom()/center() are re-seeded.
# Kept vs. re-seeded, side by side, on the same map: `clicked()` is
# *user-interaction state* -- it keeps the last click until the user clicks
# the new map. `zoom()`/`center()` are *inherent widget state* -- each
# re-render re-seeds them from the freshly built Map's own construction-time
# zoom/center. Click the map, pan and zoom it, then click "Re-render":
# clicked() is unchanged; zoom()/center() snap back to zoom=9.
#
# A kept payload can describe the PREVIOUS render's widget. If a re-render
# replaces the data a click's payload indexed into (a point index, a row
# position), the retained value can silently point at something else after
# the re-render -- see plot.clicked()'s docstring (plotly) and
# ipydatagrid's edited_cell() for the same caveat: prefer an ID-keyed lookup
# over a positional one whenever the data itself can change across a render.
from ipyleaflet import Map
from shiny import reactive
from shiny.express import input, render, ui
from shinywidgets import render_ipyleaflet
ui.page_opts(title="Across re-renders", fillable=True)
ui.input_action_button("rerender", "Re-render map")
with ui.layout_columns(col_widths=[7, 5]):
with ui.card(full_screen=True):
ui.card_header("Click, pan, and zoom, then click Re-render")
@render_ipyleaflet
@reactive.event(input.rerender, ignore_none=False)
def map():
return Map(center=(45.5, -122.6), zoom=9)
with ui.card():
ui.card_header("map.clicked() -- kept across re-render")
@render.code
def clicked_out():
pt = map.clicked()
return "None (click the map)" if pt is None else str(pt["coordinates"])
with ui.card():
ui.card_header("map.zoom() / map.center() -- re-seeded every render")
@render.code
def zoom_out():
return f"zoom={map.zoom()}\ncenter={map.center()}"Click, zoom, and pan the map – clicked() reports the click, zoom()/center() report the new viewport:

After “Re-render”, clicked() is unchanged while zoom()/center() snap back to the map’s construction-time values:

The caveat worth remembering: a kept value can describe the previous render’s widget, not the one on screen now. If a re-render swaps in new data, a retained payload’s positional field – a point index, a row position – can silently point at something else. Key off something stable instead: a customdata value (plotly), a data frame index (ipydatagrid’s .widget.data), or an ID column you added yourself. The cheat sheet’s “Across re-render” column marks every accessor kept vs. re-seeded.
A kept payload can also dangle outright, if the re-render drops the data it referenced – an unguarded next(row for row in rows if row["id"] == kept_id) then crashes with StopIteration inside the reactive flush. Guard the lookup (filter and check .empty, or use .get() with a default) and treat an unresolved payload as “nothing selected” rather than letting it crash the output.
Read on demand
Because an accessor records from the moment its output renders, a gesture made before any code reads it is never lost. You can read an accessor on demand – from a button handler, a @reactive.event-gated output, a download handler, a chat message handler, or a tool an LLM decides to call – long after the user interacted, with nothing lost in between. (An opt-in accessor still needs its listen_to declared up front; it’s only the read that can wait.)
examples/09_read_on_demand.py makes this concrete: nothing reads plot.selected_rows() until the user clicks a button, and the selection made before that click is still there when it finally runs.
# Read on demand: `listen_to=["selected_rows"]` opts this app into the selection
# stream (the payload grows with the selection, so plotly's selection
# accessors are off unless declared), but nothing READS
# `plot.selected_rows()` until the button's gated reader runs -- not a
# warm-up effect, not a visible output, nothing. Box- or lasso-select points
# FIRST, then click "Show selection": the selection you already made is
# there, because once declared the accessor records from the moment the
# plot renders, not from its first read. This is what makes a selection safe
# to read from a button handler, a `@reactive.event`-gated output, a
# download handler, or (see the ai-exploration article) a chat message
# handler or an LLM tool call -- any reader that only runs after the user
# has already interacted.
import plotly.express as px
from shiny import reactive
from shiny.express import input, render, ui
from shinywidgets import render_plotly
df = px.data.iris().reset_index(drop=True)
ui.page_opts(title="Read on demand", fillable=True)
with ui.layout_columns(col_widths=[7, 5]):
with ui.card(full_screen=True):
ui.card_header("Lasso or box-select points, THEN click the button")
@render_plotly(listen_to=["selected_rows"])
def plot():
fig = px.scatter(
df, x="sepal_width", y="sepal_length", custom_data=[df.index]
)
return fig.update_layout(dragmode="select")
with ui.card():
ui.input_action_button("show", "Show selection")
ui.card_header("Only reads plot.selected_rows() once clicked")
@render.data_frame
@reactive.event(input.show)
def selection_out():
return render.DataGrid(plot.selected_rows(df))Box-select a region; nothing has read it yet, so nothing shows it:

Click the button, and the selection made before it is there in full:

The same pattern makes it safe to hand a selection to a chat interface or an LLM tool: the user lassos a region, then starts chatting, and the model calls a registered tool that reads plot.selected_rows() on its own schedule. The ai-exploration article builds this out fully, with a worked example where a registered tool reads a lasso selection this way.
Re-firing and clearing
A dedup rule applies to almost every accessor: a value equal to what it last published doesn’t invalidate readers, so clicking the same point twice only fires once. examples/03_refire_and_clearing.py counts fires (via an effect, using reactive.isolate() – see Writing back for why) for two plotly accessors on the same figure: clicked() (dedups) and double_clicked(), a pulse that doesn’t.
# Re-fire and clearing semantics, using two plotly accessors on the same
# figure. An effect counts how many times each accessor's value actually
# changes (using `reactive.isolate()` so the counter doesn't depend on
# itself; see "Writing back" in the Updating in place article for why that
# matters):
#
# - `clicked()` dedupes by value (input priority): clicking the SAME point
# twice publishes the same value twice, but the counter doesn't advance on
# the second click. A double-click that lands on a MARKER re-fires
# `clicked()` (the second click of the pair is a normal click on that
# point) -- it does not clear. A double-click that lands on the BACKGROUND
# clears `clicked()` back to None (plotly's own "double-click resets the
# view" gesture).
# - `double_clicked()` is a *pulse*: it fires `True` on every double-click on
# the background and never clears, so two separate double-clicks there
# both advance the counter even though the displayed value never changes
# from `True` -- a pulse re-fires readers on an unchanged value by design,
# the opposite of `clicked()`'s dedup.
import plotly.express as px
from shiny import reactive
from shiny.express import render, ui
from shinywidgets import render_plotly
df = px.data.iris().reset_index(drop=True)
ui.page_opts(title="Re-fire and clearing", fillable=True)
fires = reactive.value(0)
pulses = reactive.value(0)
with ui.layout_columns(col_widths=[6, 3, 3]):
with ui.card(full_screen=True):
@render_plotly
def plot():
return px.scatter(df, x="sepal_width", y="sepal_length", custom_data=[df.index])
with ui.card():
ui.card_header("plot.clicked()")
@reactive.effect
def _count_fires():
plot.clicked() # depend on it
with reactive.isolate():
fires.set(fires() + 1)
@render.code
def clicked_out():
pts = plot.clicked()
state = "None" if pts is None else f"point_index={pts['point_index'].iloc[0]}"
return f"fires so far: {fires()}\nclicked(): {state}"
with ui.card():
ui.card_header("plot.double_clicked() -- a pulse")
@reactive.effect
def _count_pulses():
plot.double_clicked() # depend on it
with reactive.isolate():
pulses.set(pulses() + 1)
@render.code
def double_clicked_out():
return f"fires so far: {pulses()}\ndouble_clicked(): {plot.double_clicked()}"Clicking the same marker twice doesn’t advance clicked()’s count – it’s an exact duplicate:

A double-click on a marker clears clicked() then immediately re-sets it (two fires, net unchanged), and pulses double_clicked() too:

A double-click on the background clears clicked() to None and pulses double_clicked():

A second, separate double-click on the background: clicked() was already None, so it doesn’t fire again, but double_clicked() pulses anyway:

| Gesture | clicked() fires |
double_clicked() fires |
|---|---|---|
| Click a marker, then the same marker again | +0 | – |
| Click a different marker | +1 | – |
| Double-click that marker | +2 (clear, then re-set) | +1 (pulse) |
| Double-click on background | +1 (clear only) | +1 (pulse) |
| Double-click on background again | +0 (deduped: already None) |
+1 (pulse again) |
A pulse accessor like double_clicked() declares priority="event": it re-fires readers on an unchanged value on purpose, because the gesture itself – not the value – is what matters. If your effect does something visible on every fire (a highlight flash, a log line), a marker double-click will visibly fire clicked()‘s readers twice even though its value ends up unchanged. See the plotly guide for its other accessors’ clearing behavior, and the ipyleaflet guide for its own click/double-click story.
Rate limiting
Some widgets report a single gesture as a burst of changes, and each change re-runs everything that read it. A box-select in ipycytoscape is the extreme case: every node is its own widget, so selecting 1,000 nodes sends 1,000 separate selected updates. If an expensive calc, effect, or redraw reads those traits, one gesture queues up hundreds of re-runs and the app looks frozen until they drain, even though only the final, settled selection was worth computing. The ways out, cheapest first:
- Read an accessor that already collects the burst. ipycytoscape’s
selected_nodes()keeps one running set as nodes toggle and publishes it once the gesture settles. A loop ofreactive_read(node, "selected")over every node does the opposite: it re-runs the whole loop on every toggle. - Rate-limit the trait reads with the renderer’s
rate_policy/rate_delay(below). - Debounce the expensive step itself: put
@reactive.debounce(0.5)(or@reactive.throttle(0.5)) directly below@reactive.calc. Only the calc’s readers wait; the calc itself still runs on every change, so keep it a cheap read and do the expensive work in whatever reads it.
Every accessor has a rate policy: some declare a default (almost always "debounce", 250ms) because the gesture they report naturally streams – a brush drag, a crosshair move, a filter edit. The renderer’s rate_policy/rate_delay kwargs (e.g. @render_plotly(rate_delay=0)) let you change that, for every accessor on that output at once.
One subtlety: these kwargs only affect accessors that declare a default rate policy, plus reactive_read() calls on .widget directly. An accessor with no declared default (see the cheat sheet’s “Default rate” column) ignores rate_policy/rate_delay entirely and always publishes immediately. examples/04_rate_limiting.py compares plotly’s selecting() (debounced by default) against k3d’s camera() (no default at all), each driven by a slow drag with and without rate_delay=0:
# The renderer's rate_policy/rate_delay kwargs only govern accessors that
# declare a DEFAULT rate policy (plus reactive_read() on the root widget).
# plotly's selecting() debounces by default, so rate_delay actually changes
# its behavior; k3d's camera() declares no default rate policy at all, so
# the same kwargs are silently a no-op for it -- every raw update publishes
# immediately either way (k3d's own JS throttles camera updates to roughly
# once per 200ms, independent of anything shinywidgets does). Each panel
# counts how many times the accessor's value actually changes during one
# slow drag.
import k3d
import numpy as np
import plotly.express as px
from shiny import reactive
from shiny.express import render, ui
from shinywidgets import render_k3d, render_plotly
df = px.data.iris().reset_index(drop=True)
def counter():
n = reactive.value(0)
def bump():
with reactive.isolate():
n.set(n() + 1)
return n, bump
def k3d_points():
rng = np.random.default_rng(0)
plot = k3d.plot()
plot += k3d.points(
rng.random((200, 3), dtype=np.float32), point_size=0.05, color=0xFF0000
)
return plot
ui.page_opts(title="rate_policy / rate_delay", fillable=True)
ui.markdown(
"Drag a box slowly on each plotly figure (~1 second), and orbit-drag each "
"k3d plot slowly (~1 second), then read the counts."
)
with ui.layout_columns():
with ui.card():
ui.card_header("plotly selecting(): default debounce (250ms)")
@render_plotly(listen_to=["selecting"])
def plot_default():
return px.scatter(df, x="sepal_width", y="sepal_length").update_layout(
dragmode="select"
)
n_default, bump_default = counter()
@reactive.effect
def _():
plot_default.selecting()
bump_default()
@render.code
def out_default():
return f"selecting() fired {n_default()} times"
with ui.card():
ui.card_header("plotly selecting(rate_delay=0): every raw update")
@render_plotly(listen_to=["selecting"], rate_delay=0)
def plot_fast():
return px.scatter(df, x="sepal_width", y="sepal_length").update_layout(
dragmode="select"
)
n_fast, bump_fast = counter()
@reactive.effect
def _():
plot_fast.selecting()
bump_fast()
@render.code
def out_fast():
return f"selecting() fired {n_fast()} times"
with ui.card():
ui.card_header("k3d camera(): no default -- rate_delay=0 here")
@render_k3d(rate_delay=0, height="300px")
def plot_a():
return k3d_points()
n_a, bump_a = counter()
@reactive.effect
def _():
plot_a.camera()
bump_a()
@render.code
def out_a():
return f"camera() fired {n_a()} times"
with ui.card():
ui.card_header("k3d camera(rate_delay=2): same renderer kwarg, no effect")
@render_k3d(rate_delay=2, height="300px")
def plot_b():
return k3d_points()
n_b, bump_b = counter()
@reactive.effect
def _():
plot_b.camera()
bump_b()
@render.code
def out_b():
return f"camera() fired {n_b()} times"One slow drag on each plot shows the difference: the plotly panels diverge sharply (the debounced one fires far less often) because selecting() has a default debounce, but the two k3d panels land on the same count regardless of rate_delay, because camera() has none – k3d’s own upstream throttle is the only thing limiting it:

An accessor with no default debounce streams every raw update straight through, which can stall the browser if a heavy redraw reads it directly. Most no-default accessors in the cheat sheet stay that way; lonboard’s view_state() and ipydatagrid’s selected() are exceptions that now debounce by default – see the ipydatagrid guide for a debounced-vs-raw comparison, and the mosaic guide for the same debounce effect in library-level state (mosaic_widget’s params()).
Rows of your data
Most widgets that report a selection report it in their own coordinate space – a point index into a trace, a row position in a currently-sorted table – not a row of the data frame you built the chart from. selected_rows() (plotly, altair, bokeh, jscatter, bqplot, lonboard – itables and reactable call theirs selected()) exists to close that gap. Plotly’s version is the most explicit about the mechanism, because it has the least to go on: a point only carries whatever you told it to.
# selected_rows() turns "which points did the user select" into "which rows
# of MY data frame". Plotly (like most selection-reporting widgets) reports
# points of the figure, not rows of a data frame, so each point must carry
# its row's identity as `customdata` -- here, the pandas index, via
# `custom_data=[df.index]`. altair/bokeh each have their
# own version of this contract; see their guides' `selected_rows()` sections.
import plotly.express as px
from shiny.express import render, ui
from shinywidgets import render_plotly
df = px.data.tips().reset_index(drop=True)
ui.page_opts(title="Rows of your data", fillable=True)
with ui.layout_columns(col_widths=[7, 5]):
with ui.card(full_screen=True):
@render_plotly(listen_to=["selected_rows"])
def plot():
fig = px.scatter(df, x="total_bill", y="tip", custom_data=[df.index])
return fig.update_layout(dragmode="select")
with ui.card():
ui.card_header("plot.selected_rows(df) -- matched by df.index")
@render.data_frame
def selected():
return render.DataGrid(plot.selected_rows(df))custom_data=[df.index] is the contract: each point carries its row’s index label as customdata, and selected_rows(df) matches selected points back to df by that label – which is also why this still works on a filtered or re-sorted df (the match is by label, not position). Lassoing a cluster gets you exactly those rows, ready for a table or a downstream calculation:

For a frame without row labels (polars, or any key=-based match), pass key="id" with custom_data=["id"] instead – see the plotly guide for both forms. The same idea, different mechanics per library:
- altair:
selected_rows(name, df=...)replays Vega-Lite’s own selection test againstdf, including binned and temporal fields – see the altair guide. - bokeh:
selected_rows()reads straight from the plot’sColumnDataSource(source.to_df()), since a bokeh plot’s data source is the data frame – see the bokeh guide. - jscatter:
selected_rows(df=None)maps the lasso/click positions back into the frame theScatterwas built with (or an explicitdf, pandas or polars) – see the jscatter guide. - bqplot:
selected_rows(df, *, mark=None)maps one mark’s selected positions back intodf(required – a figure retains no data frame);mark=picks the mark for multi-mark figures – see the bqplot guide. - lonboard:
selected_rows(df=None)is the picked row ofdf, defaulting to a frame rebuilt from the pickable layer’s own data (freshRangeIndex; the default needs exactly one pickable layer and geopandas) – see the lonboard guide. - itables / reactable:
selected()returns row positions, already in your original data’s order (itables: data order, survives sort/search; reactable: data order, survives sort/filter/paging) – no customdata contract needed, because the table is rendered straight from the frame. See the itables and reactable guides.
Beyond the accessors: .read() and reactive_read()
Reach for these two in order, after the accessor methods themselves:
output.read("name")reads an accessor by name –plot.read("selected")is exactlyplot.selected(). When"name"isn’t an accessor, it falls through to a bare synced trait of the rendered widget instead, the same wayreactive_read(output.widget, "name")would. Prefer.read()over reaching forreactive_read()directly on.widget. An unknown name raisesAttributeErrorwith a “did you mean” hint built from the renderer’s own accessor names.reactive_read(obj, "trait")is for widgets that aren’t the output itself: a child widget a parent owns (an ipycytoscapeNode/Edge, an ipyleaflet layer or control), or any widget built outside a renderer. There’s no.read()for these, because there’s no renderer output wrapping them.
examples/10_read_method.py shows the first tier directly: an accessor read by name, a bare trait with no accessor, and the “did you mean” error, live.
# .read(name) is the generic way to read either an accessor (by name) or,
# when the name isn't one, a bare synced trait of the rendered widget --
# without the caller needing to know ahead of time which. `map.read("zoom")`
# below returns exactly what `map.zoom()` does (an accessor wins when a name
# is both). `map.read("scroll_wheel_zoom")` falls through to
# `reactive_read(map.widget, "scroll_wheel_zoom")`, since ipyleaflet has no
# accessor for that trait. An unknown name raises, with a "did you mean"
# hint built from the renderer's accessor names -- shown live below by
# catching it and rendering `str(exc)`.
from ipyleaflet import Map
from shiny.express import render, ui
from shinywidgets import render_ipyleaflet
ui.page_opts(title=".read()")
with ui.card(height="350px"):
ui.card_header("Pan or zoom the map")
@render_ipyleaflet
def map():
return Map(center=(45.5, -122.6), zoom=9, scroll_wheel_zoom=True)
with ui.layout_columns():
with ui.card():
ui.card_header('map.read("zoom") -- an accessor, by name')
@render.code
def read_zoom():
return str(map.read("zoom"))
with ui.card():
ui.card_header('map.read("scroll_wheel_zoom") -- a bare trait, no accessor')
@render.code
def read_trait():
return str(map.read("scroll_wheel_zoom"))
with ui.card():
ui.card_header('map.read("zooom") -- unknown name raises, with a hint')
@render.code
def read_typo():
try:
return str(map.read("zooom"))
except AttributeError as e:
return str(e)Zoom in and the accessor and the bare trait both read back correctly; the deliberately misspelled "zooom" raises with an exact pointer to the name you meant:

Two recipes for the second tier – reactive_read() on a child widget, where there’s no output to call .read() on:
- lonboard, multiple pickable layers:
selected()tells you a row was picked, across every layer, but not which layer. Read each layer’s ownselected_indextrait directly instead:reactive_read(layer, "selected_index"). See the lonboard guide’s Beyond the accessors section (examples/08_reactive_read_layer.py) for the full pattern. - bqplot: a
PanZoominteraction’s scales report the zoomed-in domain live as the user pans –reactive_read(scale, ["min", "max"])onfig.widget.marks[0].scales["x"]– and a mark’s ownselectedtrait is the one-mark escape hatch when there’s no figure-levelinteractionto intercept clicks. See the bqplot guide’s Beyond the accessors section.
To find a trait worth reading on a widget without a guide yet (or for a library-specific state no accessor covers, e.g. perspective’s theme), skim the widget class’s trait_names() for anything that looks user-facing, and reactive_read() (or .read(), for an output) it to confirm it actually updates from the browser – some traits, especially upstream-internal ones, don’t sync reliably (see each guide’s Gotchas for named examples).
Param-based libraries (holoviews, panel): panel’s param(name) accessor (e.g., slider.param("value")) now covers the common case directly – see the panel guide. holoviews and bokeh-backed render_bokeh/render_holoviews outputs still have the older escape hatch for anything a param()-style accessor can’t reach: bokeh model properties aren’t ipywidgets traits, so reactive_read() can’t see them either – reacting to them means registering bokeh’s own callbacks (source.selected.on_change(...), fig.on_event(...)) inside the render function and setting a reactive.Value from inside the callback.
Writing back
Re-rendering a widget is simple but blunt: a fresh render function call builds a brand new widget, with a brand new zoom level, a cleared selection, and (for anywidget-based widgets) another copy of its JavaScript bundle sent to the browser. For a change that’s naturally “update this one thing,” update the existing widget in place from a @reactive.effect instead – see Writing back in the Updating in place article for the full pattern, the reactive.isolate() self-trigger-loop trap, and how much an in-place update saves.
Lifetimes
A widget built directly inside a render function lives exactly as long as that render; session_lifetime() and shared_lifetime() let it outlive one. See Lifetimes in the Updating in place article for all three, the Express globals.py caveat shared_lifetime() needs, and what a shared widget means for per-user state.
Where to go next
- Updating in place: writing back to a widget without a re-render loop, and the three widget lifetimes.
- The accessor cheat sheet in this directory: every accessor on every renderer, its return type, what it reads before the first interaction, whether a re-render keeps or re-seeds it, its default rate policy, and a one-line meaning, generated from the current source.
- The ai-exploration article for a worked example of reading a selection from an LLM tool call.
- Each widget’s own guide has a full “Reacting to user interaction” section with every one of its accessors exercised individually, plus 2-4 linked-view patterns specific to that widget: start with plotly, altair, bokeh, ipyleaflet, lonboard, ipydatagrid, itables, mosaic, bqplot, panel, and reactable.