About streamlit application re running everytime there is a user_interaction


Iam trying to use filters on a dataframe that is getting dynamically updated in the code, but whenever iam trying to select a filter the code is getting rerun and the data is getting updated in the dataframe(new rows are getting added). i want a solution to stop the rerun

Code snippet:
inactive_components =
df1.loc[len(df1)] = [date_formatted,time_formatted,len(inactive_components),component_names]
def get_filtered_df(df1,_option1,_option2):
return _df1[_df1[_option1] == _option2]
with st.sidebar:
st.subheader(“Filter dataframe1”)
filtered_df = dataframe_explorer(df)
option1 = st.selectbox(“select column names”, list(df1.columns))
option2 = st.selectbox(“select values”, list(set(df1[option1])))
filtered_df1 = get_filtered_df(df1,option1,option2)

If applicable, please provide the steps we should take to reproduce the error or specified behavior.

Expected behavior:
so whenever there is a filter being applied the dataframe should be displayed with filters applied and there shouldnt be any new data added.

Actual behavior:
but whenever i try to select filters,the dataframe is getting updated

Debug info

  • Streamlit version: 1.21.0
  • Python version: Python 3.11.2
  • Using PyEnv
  • OS version:
  • Browser version:

Rerunning with every interaction is the basic structure of Streamlit.

You can put widgets into a form if you have a collection that you want a user to set before rureunning:

You can also use caching and session state to skip over parts of your code on rerun for efficiency.

After you check out those resources and maybe main concepts if you haven’t yet, feel free to edit your post so your code is formatted correctly. This will make it much easier for community members to see what you are working with. :slight_smile:


1 Like

thank you @mathcatsand

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.