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

1 Like

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

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.

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.