Skip to content

plotly: accept selected_rows as a listen_to alias for selected - #520

Open
cpsievert wants to merge 1 commit into
fix-opt-in-error-method-namefrom
feat-listen-to-selected-rows
Open

cpsievert wants to merge 1 commit into
fix-opt-in-error-method-namefrom
feat-listen-to-selected-rows

Conversation

@cpsievert

Copy link
Copy Markdown
Collaborator

Why

The rule for opting into a plotly accessor is "pass the name of the method you call to listen_to." That broke for selected_rows(df): it reads the selected accessor internally, so a caller who only ever writes plot.selected_rows(df) still had to know to write listen_to=["selected"] -- a method they never call. listen_to=["selected_rows"] is now accepted too and enables the same accessor, so the rule holds for every public method.

# Before: works, but "selected" never appears in this app
@render_plotly(listen_to=["selected"])
def plot():
    ...

@render.data_frame
def picked():
    return plot.selected_rows(df)

# After: write what you read
@render_plotly(listen_to=["selected_rows"])
def plot():
    ...

Both spellings stay valid (and passing both is fine); selected()/selected_rows() remain separate methods -- this only changes what you pass to listen_to. The opt-in error you get from calling selected_rows() without opting in now also suggests listen_to=["selected_rows"] instead of ["selected"].

Stacked on #518.

Implementation notes

  • AccessorSpec gains an aliases field; plotly's SELECTED spec sets aliases=("selected_rows",).
  • listen_to is normalized to canonical accessor names once, at the render_widget_base/Accessors boundary, so opt-in gating, muted-trait suppression, and unknown-name validation all see canonical names without extra alias-handling at each site. Unknown-name errors now list aliases among the valid names.
  • _read_accessor/Accessors.read's call kwarg (added in Name the calling method in opt-in accessor errors #518) now drives both the displayed method and the listen_to suggestion from one value, so selected_rows()'s error suggests "selected_rows" while direct selected() calls keep suggesting "selected".
  • Docs, examples, gallery apps, and the bundled skill references are updated everywhere the code only reads selected_rows() (not selected() itself); sites that call selected() directly keep ["selected"]. website/guide/ai-exploration/ is intentionally left untouched -- it's being rewritten on another branch.

Users who only ever call plot.selected_rows(df) had to know to write
listen_to=["selected"] -- the accessor they never call by that name.
AccessorSpec now takes an `aliases` field; plotly's SELECTED spec
declares aliases=("selected_rows",), and listen_to is normalized to
canonical accessor names once at the render_widget_base/Accessors
boundary, so every downstream check (opt-in gating, muted-trait
suppression, unknown-name validation) sees canonical names without
needing its own alias handling. The opt-in error for selected_rows()
now suggests listen_to=["selected_rows"]; selected() keeps suggesting
["selected"] (the `call` kwarg to _read_accessor/Accessors.read now
drives both the displayed method and the listen_to suggestion from
one value).

Docs, examples, gallery apps, and the bundled skill references are
updated everywhere the code only reads selected_rows() (not
selected() itself); call sites that read selected() directly keep
["selected"]. website/guide/ai-exploration/ is intentionally left
untouched (being rewritten on another branch).

This branch has not been deployed

No deployments
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.

1 participant