Strange and Subtle Refresh Streamlit Bugs

Has anyone else noticed that streamlit appears to have a few strange and subtle bugs? Iā€™ve noticed a couple oddities:

  1. Sometimes streamlit reloads unexpectedly and all multi-select widgets are reset to their default values. However, based on what code runs, the values returned by the widgets still seem to be the old values for the first such run of the app. Then the next time the user modifies a widgetā€™s value the default values of the multi-select widgets end up being used instead.
  2. Sometimes an entire streamlit app crashes unexpectedly and the page needs to be refreshed. This can happen either when entering input or while waiting for code to rerun. Itā€™s probably not related, but Iā€™ve become wary of scrolling up and down the page and interacting with already-plotted alt-air charts while waiting for code to run because it sometimes appears to induce these crashes.

I would try to create a minimal working example of these, but Iā€™m not really sure how to reproduce these bugs ā€“ they only happen some of the time when I run my app.

Has anyone else experienced similar issues? They seem to occur infrequently enough that they are more of an annoyance than a problem for my purposes, but they are still frustrating to have to deal with.

It may be unrelated, but one of the issues mentioned in this question sounds a bit similar. Avoid rerunning for intermediate values for number_input, slider etc

3 Likes

Hey @Yasha,

Answering to your questions:

  1. Streamlit does a rerun everytime that is some change either in the script or a change made by the user within the App. There are some cases that you could need to store the state between reruns you could solve that using st.cache or ā€œSession Stateā€ like is shown in this discussion

  2. We are going to be needing an example to try it out

Please let us know if this helps you

1 Like

Hi @arraydude

  1. Yep, I know. thatā€™s not the kind of rerun that Iā€™m referring to. Iā€™m talking about reruns that occasionally happen outside of those two cases.
  2. Fair enough. Unfortunately, as I said, I am unable to reliably reproduce either of these two bugs. They appear to happen at random as far as I can tell.

Unfortunately your answer was no help. However, I know I didnā€™t give you much to work with, so I didnā€™t expect a solution. Iā€™m mostly curious to know if others have encountered similar issues.

1 Like

I was able to reproduce the case when nothing update (including the page content: itā€™s totally white).
Consider two files,
code.py:

import streamlit as st
import pandas as pd

st.write("""
# My first app
Hello *world!*
""")

df = pd.DataFrame({
  'x': list(range(100)),
  'y': list(map(lambda x: x*x, range(100)))
})

st.line_chart(df)
st.table(df)

and script.py (which started by stremlit run)

import code

then first time you change anything the show does. After page refresh, there are none.

Workaround: wrap other files code to function and call it

Hello @api_access

Youā€™re encountering this behavior because streamlit wonā€™t re-import everything when you re-run your script.py, thus your code.py's body wonā€™t be re-executed. By wrapping everything in a function like you said, you can explicitly call it in script.py to execute everything.

@Yasha, is this what you are talking about? Notice here in below gif, I am selecting No for both the radio buttons and then suddenly the page reloads and the values are reset to default Yes again. I donā€™t know how to tackle this! Maybe I am doing something wrong or I am missing something.

Also this happens only like 6 out of 10 times or so, not always!

ezgif.com-video-to-gif

An additional gif for more clearer demonstrationā€¦

ezgif.com-video-to-gif (1)

2 Likes

Hi Benison_Sam (welcome!) Thanks for reporting this issue. A couple quick questions:

  • What version of Streamlit youā€™re running?
  • Do you have the source of the app somewhere, or a reproducible test case we can run?
1 Like

@AustinC

I have encountered the same issue several times, particularly if there are a lot of user inputs.
My version is 0.71.0. Unfortunately, I cannot share the source code and it is not possible to reliable reproduce the error since it is unpredictable. However, my error is basically the same error Benison_Sam presented via gif.

Example: My app has ā€œMain Pageā€ and a few other ā€œpagesā€ which are not related to each other (each page contains code and functions which are ran only on that page). After I complete some task on ā€œPage 1ā€ and go to ā€œPage 2ā€ to complete some other tasks, sometimes the whole app refreshes after I click a button or upload a file and it returns me to ā€œMain Pageā€. When I go back to ā€œPage 2ā€ I can see that the files are uploaded, but I have no idea why it returned me to ā€œMain Pageā€.

P.S. Different pages were handled via st.selectbox()

Thank you in advance!

I have run into this issue as well.

Something similar to what @Benison_Sam has illustrated happens. Sometimes my application, when running cross-validation computations, will suddenly stop and reset everything. I am using version 0.72.0.

I cannot share the source code and, like the others have stated, this is something that only happens sometimes thus it is hard to reproduce the error.

Hello everyone,

Those refreshes can be a real Streamlit bug, or some code flow issue in your apps.
Unfortunately with no code sample, Itā€™s going to be hard to identify whatā€™s the matter.

Hello everyone,

I have added a snippet of my original code to this repo with instructions under the README.md file on how to try to reproduce this strange behaviour. Then again, it might be hard to do reproduce it as it presents a somewhat random nature, but I have noticed, on my specific application, that it is more common when the Yearly seasonality parameter is set to True.

After pressing the Validate button the app will appear to be running smoothly for a few iterations of the process and then, all of a sudden, the text on the top right-corner will change from RUNNINGā€¦ to CONNECTINGā€¦ (see images below) and the app will completely reset.

Running:

Connecting:

Let me know if you have any ideas on this issue.
Thanks in advance!

1 Like

Hi @ruimaia!
I was going over your issue and I think I have a similar one. I have an app that does a heavy computation, when clicking a button called ā€œsubmitā€, in the background and Streamlit seems to work at the beginning just fine. This computation has an extra step that takes around 30 mins to complete (or more) that can be enabled by clicking on checkbox (disabled by default). While that checkbox is set as False, Streamlit runs the computation and shows the results correctly (I havenā€™t had any weird reload issues here). Now, when the checkbox is set as True, the first part of the computation is made but then suddenly Streamlit reloads and goes back to the original main page as if nothing has happened. In my case, the state of ā€œRunningā€ doesnā€™t change to ā€œConnectingā€, it just reloads and goes back to the original, but I think it is indeed related with certain components as checkboxes or selectboxes.

Were you able to find the issue at the end?

Thanks a lot!
David.

Hi, @avila196!

I was not able to find the issue, sorry.

Hi Streamlit team,

Iā€™m experiencing the same issue that @Benison_Sam noted some time ago. Please have a look at the video below:

Screen Recording 2022-08-10 at 12.44.56

The code can be found at: GitHub - DavideFerri/streamlit_bug

Could you please help me with this?

1 Like

Another example:

Screen Recording 2022-08-10 at 12.58.29

Hi @Davide_Ferri :wave:

You could file a bug report to bring this issue to the attention of our devs if itā€™s happening on the latest Streamlit version:

Hi @snehankekre, thank you! I have filed the report here: Input widgets refresh bug Ā· Issue #5125 Ā· streamlit/streamlit Ā· GitHub

1 Like

Hey anyone new info on this random bug? Iā€™m also experiencing this without being able to pinpoint the random full refresh behavior, the full reset appears to be completely random

let me support with my case, i use streamlit form that when user input something and submit, it will load and display images. After all images are load and display successfully, it keeps images showing perfectly. however after a random time, it refresh and all displaying images are gone. user has to start all over again to see images. Still figuring out how to fix this.