streamlit-plotly-events

raw JSON →
0.0.6 verified Fri May 01 auth: no python

A Streamlit component that wraps Plotly charts and enables capturing events (e.g., click, hover, select) from the chart and passing them back to Streamlit for reactive updates. Version 0.0.6 requires Python >=3.6, currently in early/experimental stage with infrequent releases.

pip install streamlit-plotly-events
error ModuleNotFoundError: No module named 'streamlit_plotly_events'
cause Library not installed or installed incorrectly (e.g., hyphens in name).
fix
Run 'pip install streamlit-plotly-events' and use import 'from streamlit_plotly_events import plotly_chart'.
error TypeError: plotly_chart() got multiple values for argument 'click_event'
cause Passing click_event as positional argument instead of keyword.
fix
Always use keyword arguments: plotly_chart(fig, click_event=True)
error AttributeError: 'NoneType' object has no attribute 'append' (or similar)
cause Trying to iterate over None when no event has occurred.
fix
Check for None: if selected_points: ...
error streamlit.runtime.scriptrunner.script_runner.ScriptRunnerException
cause Incorrect event parameter name (e.g., 'on_click' instead of 'click_event').
fix
Use the correct parameters: click_event, hover_event, select_event.
gotcha Event arguments (click_event, hover_event, select_event) must be passed as keyword arguments; they are not positional.
fix Always use keyword arguments: plotly_chart(fig, click_event=True)
gotcha The component returns None when no event has occurred. Always check for None before iterating.
fix if selected_points: st.write(selected_points) to avoid AttributeError
gotcha The library does not support all Plotly chart types; complex layouts or subplots may cause silent failures or errors.
fix Stick to simple, single-trace figures. Test thoroughly.
breaking Version 0.0.5 removed the old 'streamlit-plotly-events' import path; use 'streamlit_plotly_events' (underscore).
fix Replace 'import streamlit_plotly_events' (with hyphens) with 'from streamlit_plotly_events import plotly_chart'.
deprecated The 'start_event' and 'end_event' parameters were deprecated in 0.0.4 and removed in 0.0.5.
fix Use click_event, hover_event, select_event instead.

Minimal example: render a scatter plot and capture click events. Returns list of dicts with point and curve info.

import streamlit as st
import plotly.graph_objects as go
from streamlit_plotly_events import plotly_chart

fig = go.Figure(data=[go.Scatter(x=[1,2,3], y=[4,5,6], mode='markers')])
selected_points = plotly_chart(fig, click_event=True, hover_event=False, select_event=False)
if selected_points:
    st.write(selected_points)