Avoiding complete reruns during the plotly events like mouse clicks on the graphs

First post :slight_smile:

Hi Streamlit community,

I’m working on an interactive Streamlit dashboard using st.plotly_chart, but I’ve run into an issue with rerun behavior. Whenever a user interacts with a widget or a Plotly element - like trying to censor a datapoint from the graph, the entire app script reruns from top to bottom, causing unnecessary recomputation and lag—especially with multiple charts or heavy data processing.

Is there a way to:

  • Prevent the entire app from rerunning when updating Plotly charts?

  • Achieve partial reruns or selectively update only the affected chart/container?

  • Use session state, containers, or any experimental fragment rerun features for this?

  • Any best practices or code patterns recommended for handling Plotly chart updates efficiently in Streamlit?

I want the app to stay responsive and avoid rerunning unrelated parts of my code. Any advice or examples would be greatly appreciated!

Thanks in advance!

Streamlit version: 1.38.0
Python version: 3.11.3

Welcome to Streamlit :balloon:

The first thing I’d recommend is to use the latest version of the Streamlit API - 1.50.0 as of today.

You can use fragments to selectively rerun parts of the app :backhand_index_pointing_right: Working with fragments - Streamlit Docs

WRT reducing recomputation, take a look at caching :backhand_index_pointing_right: Caching overview - Streamlit Docs

1 Like

Thank you, Siddhant! I had looked into the topics of fragments, caching and had implemented them. I however did the streamlit update now. I think I have optimized it to a good extent. I just have a request to the streamlit developers to look into this in the next update - of a feature like form submit to collect the plotly event inputs and then give submit for the rerun. This would be quite helpful. Thank you

If anybody has any other work around, please let me know

Can you create a feature request here: New Issue