I’m building an embedding visualizer for drift detection using Streamlit + Plotly. I need to:
- Click on a scatter point (embedding)
- Get a URL from
customdata
- Load and display the image
I’ve tried using streamlit-plotly-events2
and also st.plotly_chart(..., on_select="rerun")
, but both approaches are either too slow (2–3s lag) or don’t reliably capture multiple clicks.
Here’s a minimal working example ):
clicked_points = plotly_events(fig, click_event=True, key="plot_click")
if clicked_points and 'pointIndex' in clicked_points[0]:
idx = clicked_points[0]['pointIndex']
url = current_urls[idx]
st.image(fetch_image_from_url(url)) # simplified
But clicks are flaky — sometimes the plot refreshes but no point is selected. Other times it’s just slow.
How do i
- Reliably capture click events?
- Extract
customdata
from the clicked point? - Avoid the latency or missed clicks?
Any working example or guidance would be appreciated!Im doing it in my local itself