Proper use of on_change with st.experimental_data_editor

Did not work unfortunately. Which is odd because I use very similar code to exactly what you provided at a different point in my script. As a matter of fact, at other points in my script, the code does exactly what I want. The exact problem n this section is that when I modify a value in edited_df, the first modified value is saved, but when i modify a second value in edited_df, the script rerun resets the second modified value, but keeps the first modified value. This problem continues no matter how many modifications I make. Eventually, all modifications can be saved, but it requires double input for essentially all of them.

I am wondering if it is because of the nature of df. In this specific section of my code, df is not hard-coded, but rather pulled from a database, specifically, it is pulled from ‘mytable.’ I am wondering if the fact that I am updating ‘mytable’ with my function, and then calling df again with every script rerun is essentially reseting the original value of edited_df. When I include st.write(st.sesion_state) I can see that the first modification is saved, but upon the second modification, it resets. See what I mean below


def update(conn, edited_df, column, notes):
     for row_1, row_2, row_3 in zip(edited_df['col1'], edited_df['col2'], edited_df['col3']):
         cursor.execute('INSERT INTO mytable VALUES %s, %s, %s', (value1, value2, value3,))

def check_if_exists(conn, name):
    cursor=conn.cursor()
    ## some code
    if exits:
            st.write("## Data in 'mytable'! Continue modifying?")
            
            #Getting table for query
            cursor.execute(f"""SELECT * FROM mytable WHERE id = %s
            """, (id,))

            rows=cursor.fetchall()

            df=pd.DataFrame(rows)
            if "df_value" not in st.session_state:
                st.session_state.df_value = df 
            edited_df=st.experimental_data_editor(df, num_rows='dynamic')
            try:
                if not edited_df.equals(st.session_state["df_value"]):
                    update(conn, edited_df, name, workout_number)
                    st.session_state['df_value'] = edited_df

I run similar code somewhere else in script where I pull from a database ad modify in st.experimental_data_editor, but each modification doesn’t modify the original table that represents df, and that works as expected so curious if you think that is the problem.