Click events in plotly_chart

I use plotly_chart which fits perfect to the window dimensions as I put in figure a large width. I need to have a on_click callbak to catch everytime a user click a point on the chart.
I have tried using plotly_events but it destroys all figure format, making the graph smaller, no matter what parameters I give it.

Any other way to use streamlit with a graph but with ability to have on_click callback function?

import streamlit as st
import plotly.graph_objects as go
from plotly.subplots import make_subplots
from streamlit_plotly_events import plotly_events

fig = make_subplots()
fig.add_trace(go.Scattergl(x=[1,2,3,4,5,6], y=[1,2,3,4,5,6]))
fig.update_layout(width=1100)
#st.plotly_chart(fig, template=ā€˜plotly_white’)
selected_click = plotly_events(fig, click_event=True)

Hi @Michel39

Could you share a code snippet of your app that reproduces this error. This would be helpful to the community in helping to resolve your issue.

Thanks!

You can try the code below one time as it is as now and one time with st.plotly_chart (in comment below) instead of plotly_events.
You can see there difference. I want plotly_events to be the same as with st.plotly_chart in chart width without cutting it in the middle. How to do it?
also override_width as True/False did not help. I would be happy to any help.

import streamlit as st
import plotly.graph_objects as go
from plotly.subplots import make_subplots
from streamlit_plotly_events import plotly_events

fig = make_subplots()
fig.add_trace(go.Scattergl(x=[1,2,3,4,5,6], y=[1,2,3,4,5,6]))
fig.update_layout(width=1100)
#st.plotly_chart(fig, template=ā€˜plotly_white’)
selected_click = plotly_events(fig, click_event=True)

Hey @Michel39!

We don’t support chart selections yet but we’re working on it. See my update here. There’s also a prototype you can have a look at to see how it will work. I’ll update that GitHub issue once we are getting closer to a release.

Cheers, Johannes

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.