Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

fix: clear plotly selection (double click) (#1181)

Myles Scolnickbea78b251363
diff --git a/frontend/src/plugins/impl/plotly/PlotlyPlugin.tsx b/frontend/src/plugins/impl/plotly/PlotlyPlugin.tsx
index 592378ed0b..34089fa83d 100644
--- a/frontend/src/plugins/impl/plotly/PlotlyPlugin.tsx
+++ b/frontend/src/plugins/impl/plotly/PlotlyPlugin.tsx
@@ -164,6 +164,25 @@ export const PlotlyComponent = memo(
setValue((prev) => ({ ...prev, ...obj }));
}
}}
+ onUpdate={(figure) => {
+ // If the user double-clicks, all selection will be cleared
+ // But this does not call onSelected, so we need to clear it here
+ const selections =
+ "selections" in figure.layout &&
+ Array.isArray(figure.layout.selections)
+ ? figure.layout.selections
+ : [];
+ if (selections.length === 0) {
+ console.log("Clearing selections");
+ setValue((prev) => ({
+ ...prev,
+ selections: selections,
+ points: [],
+ indices: [],
+ range: undefined,
+ }));
+ }
+ }}
config={plotlyConfig}
onSelected={useEvent((evt: Readonly<Plotly.PlotSelectionEvent>) => {
if (!evt) {