I am running this app locally:
import streamlit as st
st.button("A button that should do nothing!")
#######################################################################
st.divider()
# Something unrelated to my things:
text1 = st.text_input("Text1")
st.write(f"Doing something with: >{text1}<")
#######################################################################
st.divider()
# st.rerun example use case
if 'my_things' not in st.session_state:
st.session_state.my_things = []
st.write("My things:")
for thing_name in st.session_state.my_things:
st.write(thing_name)
if st.button("Create thing"):
st.session_state.my_things.append("Thing-string!")
st.rerun() # Rerun to display thing!
#######################################################################
st.divider()
# Something unrelated to my things:
text2 = st.text_input("Text2")
st.write(f"Doing something with: >{text2}<")
Python 3.12.3, Streamlit 1.33.0
In this script, I have 2 text_inputs, one above the st.rerun and one below it.
If I enter “hello world” into both boxes, I immediately see it on the output. But if I press the “Create thing” button, the script re-runs, the first text remains as expected, but the second text becomes an empty string. Now it obviously displays the second text_input and the written text, so it’s run, but for some reason it seems to return an empty string instead of the input text. A simple rerun, such as the pressing the top button is enough to run the entire script and display the text correctly again. The top text is unaffected, as expected.
I am trying to wrap my head around this. Is this expected functionality? Why does this happen? Thanks