Hello,
This is my first post so first of all thanks to the community and everyone helping and contributing!
After searching through the forum and the internet I did not seem to find the answer to my problem:
I am using plotly_events to plot a chart on which I activate a click_event function to get and save data of the point clicked on the graph.
Now the problem is that my app has a sidebar and when creating the chart I can’t format the figure so that it fits in the screen. When the sidebar is open the chart’s right side is out of the screen, but when the sidebar is closed the whole chart is within the screen.
The chart is plotted with: plotly_events(chart, click_event=True)
On the other hand when the chart is created with st.plotly_chart() it fits perfectly with in the app screen.
I have tried passing st.plotly_chart() to plotly_events( st.plotly_chart(), click_event=True).
which solves the displaying problem but then the click_event is not working.
Hi @nirco13 ! Thanks for posting your problem. It’s great to hear about your problems.
Can you possibly post the code where it is working and it’s not working? I can try debugging it. Maybe it’s a bug for streamlit and maybe it could be a great find
Hi @willhuang,
The app includes an interactive chart that the user can change.
Following is the code where the chart is not fitted to the app screen unless I force it using predefined width and height.
plotly_events it is a built-in function of streamlit_plotly_events module create_chart it is just a function that returns a plotly figure based on data from a dataframe.
Here’s the function structure:
Sorry, I probably should have mentioned that I’m using additional modules.
I believe what you are missing is the following import which comes from streamlit_plotly_events module:
from streamlit_plotly_events import plotly_events
Other than that all other imports are pretty standard (streamlit, plotly.express, plotly.graph_objects)
Hi @nirco13 , sorry for the late reply. what would be the df and go be? Are those packages? Is it possible to copy and paste that is easily reproducible for me? Otherwise I would have to search for all the packages and guess on some of the code.
Usually df stand for a pandas dataframe and go for plotly graphic objects.
Instead of the df you can use simple arrays like np.array([1,2,3]).
The goal here is to understand how to use the streamlit keyword use_container_width within the community component plotly_events .
Has there been any solution to this problem? I have been experiencing the same issue. The app that I am building contains a charts created from both plotly_events() and st.plotly_chart(). If I change the zoom of my page, the plotly_chart() graph will adapt its size however the the one using st.plotly_chart() will not. The screenshot below shows this (the top graph has been cut off).
This is because the plotly_events function is not an additional function. It is completely replacing the plotly_chart function.
Unfortunately plotly_events does not the exact thing as plotly_chart does. For example you lose all colors. So you can either have “graph with colors” (with plotly_chart) or you can have “graph with events” (with plotly_events). But you can not have both.