Entire app refreshes when I move slider

Hey there!

Could use a bit of help. I have an app that displays a Plotly bar chart, and I have created a slider to change the number of bars shown on the chart. Unfortunately, every time I move the slider, the page refreshes and I start over again.

There’s no error message, so I don’t even know what the underlying cause is. The closest thing I have found in other forum posts is something about States, but I’m not sure what to do about that.

Someone else had this problem several months ago, and it hasn’t been answered yet either.

Any help would be much appreciated!

Hi EricPostMaster,

Welcome to the community! :slight_smile:

What you are experiencing is not a bug, but a core element of how Streamlit works. Everytime you interact with a widget, the script will rerun. This is what allows Streamlit apps to be so simple, but it is also devious! Because every computation is rerun when interacting with widgets it is a good idea to use caching for expensive computations. And in general, try to structure the code with this feature of Streamlit in mind :slight_smile:

Peter Emil

1 Like

Awesome, thanks for the intel. I am still trying to figure out the caching thing, but I was at least able to get things working!