St.form showing old results even when input is cleared. 2nd form is updating based on input in 1st form

Hi, I have a function that recommends 3 random but similar cities, based on an input of the users current city. And another function that recommends 3 random, non-similar cities.
I am using st.form, st.text_input and submit_button for each function.
I am new to Streamlit and have 2 problems:

  1. When clearing out the input city, the results from the previous input still remain. Even when refreshing the page. Is there are way for the form to reset after the input is cleared out?

  2. When submitting an input for my first st.form (similar city), the 2nd st.form (non-similar city) populates based on the input in the first form. And vice versa.

This is the code I am using to put my function on streamlit:

#take user city as input
with st.form(key=‘my_cities’):
my_city = st.text_input(label=“Enter your current city (City, Country):”)
submit_button = st.form_submit_button(label=‘Get my next living destination!’)
similar_city_recommendations(city_country = my_city)

I would like the results to clear once the text box is cleared. I am making a demo video and I can’t have the previous results shown in the demo.

Again, both forms update based on input from just 1 form.

Any guidance would be appreciated!!

Using Streamlit version 0.87.0 and python version 3.8.8

1 Like

Just signed up but I think the clear_on_submit = True should work for this issue.