Streamlit Autorefresh

Hey @HHest

Hmmm, based on the error you are providing, it seems like it’s a web socket problem. Let me see if my colleague knows more what’s going on.

Thank you very much @kmcgrady. I’ll try to replicate with a small example as well.

Hi @kmcgrady, will this solve the auto refresh issue of app on streamlit cloud? If I add st_autorefresh(interval=8*60*60*1000, key="no_update_for_8h"), will this avoid auto refresh issue for 8h for the deployed app on cloud?

Hey @SqTao .

Assuming you do not use the component, this would not fix the auto refresh issue. This might be a Streamlit cloud challenge. I believe the issue got a comment that explains this.

Sorry this does not solve your challenge! :frowning:

1 Like

Hi @kmcgrady
I know this was design for streamlit, which I was using with great happiness, but now I started using it with plotly-dash, and it makes the color of the bars black, when I remove it, the colors are back, I am working on Python 3.9.

Any idea why that would be?
Thanks

That’s really awesome! Thanks for sharing will look into this idea

Hey @arafeek . I have not played with plotly dash, so I do not know. Is there a way for Plotly Dash to support Streamlit custom components? I wasn’t aware of any way. If you can point me to a resource, I am happy to look into it.

Hi again,
Thanks for the prompt response, I actually just discovered that this will happen simply by importing the module, all you need is to add

from streamlit_autorefresh import st_autorefresh

After that, you will be stuck, restarting the kernel does not reset the colors, nor deleting the variables. I am using Spyder (the latest) with Python 3.9, and the only way to have the colors back is by starting a new file and copy the code (without this import)

That is so weird, but honestly, I don’t think it will properly work in plotly dash. This component sends a streamlit specific message to the frontend, and the autorefreshing is triggered from the frontend. It even requires Streamlit under the hood. I cannot see (from my searching) how it would work properly (impressed it won’t even error).

I wish I could help. I’d probably look at the Plotly Dash’s Live Updating mechanism

Amazing!!!!!

hi @kmcgrady
I am developing a streamlit application that displays data that changes for every n minutes i used st_autorefresh to rerun my code after that n minute interval , but if there is any user_interaction between that n minutes (suppose take the user-interaction was at n-2 minutes) the code is being runned at n minutes after the user interaction and not at n before the user interaction , can anyone please provide a solution for this,

appreciate any replies
Thank you

1 Like

Hi all!

I’ve been using this component for some months now for a real-time dashboard i’ve been working on and it has been really helpful.

One thing I noticed, is how memory consumption increases as the interval parameter decreases. When the refresh rate is set to 1 min, memory consumption is around 150 mb on average no matter how long the app is running. When the dashboard refreshes every second, the memory consumption increases very fast. In about 4-5 hours it has reached close to 1.5 gb of memory consumption.

I’m trying to debug the issue, but I’m not sure where to start. Any ideas? The app is collecting data. It would be really helpful if the dashboard refreshed every second and let it run for days.

Maybe the python garbage collector doesn’t release memory when the dashboard refreshes too often (?)

Last, whenever I close the chrome tab and open a new one, the memory consumption goes down to 100-120 mb and the cycle repeats itself.

Hey @a.man

Sorry for the delay. I was out for the holidays.

Memory leaks can get very complicated. We have noticed in our testing that often the Python heap grows and doesn’t get cleared right away. We already run with the flag runner.postScriptGC to True, so every script run executes the garbage collector.

Are you 1. using the latest Streamlit, and 2. do you have any graphs from say memray that explain the memory consumption over time?

Thank you!