Save a dataframe using session state with streamlit v0.84

I am using streamlit to build a web app that includes a selectbox where the app initialize a dataframe and allow the user to filter this datafarme based on his required criteria then the system display the new datafarme after that the user can select the record from a selectbox that he want to update based on the index number of the new dataframe.

The problem is that when the user select a value from the selectbox the page refresh and nothing is happen.

what i want is to be able to preserve the new dataframe (filtered dataframe) in order to allow the user to select the desired index number.

streamlit version : 0.84

code:


import streamlit as st 
import pandas as pd 

df = pd.read_sql_query('select * from testDB.dbo.t1',con)
with st.form(key='Search_form'):
       all_columns = df.columns.tolist()
       st_input_update = st.number_input if is_numeric_dtype(all_columns) else st.text_input
       search_term=st_input_update("Enter Search Term")
       if 'search_term' not in st.session_state:
             st.session_state.search_term = search_term
                               
       if st.form_submit_button("search"):
              if len(search_term)>0:
                   sql='select * from testDB.dbo.t1 where  last LIKE  ? or first LIKE ?  '
                   param0=f'%{search_term}%'
                   param1=f'%{search_term}%'
                   rows = cursor.execute(sql, param0,param1).fetchall()
              st.session_state.search_term = search_term 
              df_result_search = pd.DataFrame.from_records(rows, columns = [column[0] for column in cursor.description])
st.write(st.session_state)        
if 'df_result_search' not in st.session_state:
         st.session_state.df_result_search = df_result_search
         st.write("you are out of  the session")
else:
         st.write("you are in the session")
         st.session_state.df_result_search = df_result_search
                        
st.dataframe(st.session_state["df_result_search"])

df_len = range(len(df_result_search.index))
with st.form(key='ss_form'):
           s = st.selectbox('Select index',options=df_len)
           if 'select_box_val' not in st.session_state:
                       st.session_state.select_box_val = s
           st.session_state.select_box_val = s
           if st.form_submit_button("select"):
                       st.write("you select: {}".format(s))

the wrong output :

how to save the df after changing value in selectbox usig session state