Data_editor - Not returning edited data on button click

Hello, I’m new to Streamlit and I appreciate if you could suggest solutions for the issue I’m having.

The idea is to get edited values in “edited_col” column on submit (so that I can update database record).

The issue I’m having is that I have to click Submit button twice to get it to work. Also the table value unexpectedly reset value as well.

Potential Cause
I think it is caused by the data_editor not returning the edited result at the button onclick event.

Potential Solution?
Would you be able to tell me if there is a way to force data_editor to return the edited result? or may be better ways to make this work somehow please?

Thank you.

I’m testing script below on
(Streamlit v1.24.0)

import streamlit as st
import pandas as pd

df = pd.DataFrame(
       {"Type": 3, "ROW_ID": 6, "edited_col": "etc", "rating": 4, "is_widget": True},
       {"Type": 1, "ROW_ID": 7, "edited_col": "st.selectbox", "rating": 4, "is_widget": True},
       {"Type": 1, "ROW_ID": 8, "edited_col": "st.balloons", "rating": 5, "is_widget": False},
       {"Type": 2, "ROW_ID": 9, "edited_col": "A", "rating": 3, "is_widget": True},
       {"Type": 1, "ROW_ID": 10, "edited_col": "B", "rating": 3, "is_widget": True},
       {"Type": 2, "ROW_ID": 11, "edited_col": "C", "rating": 3, "is_widget": True},
       {"Type": 2, "ROW_ID": 12, "edited_col": "D", "rating": 3, "is_widget": True},
       {"Type": 2, "ROW_ID": 13, "edited_col": "F", "rating": 3, "is_widget": True}

if "df" not in st.session_state:
    st.session_state.df = df[df["Type"].isin([2])]

with st.sidebar:
    if st.button("obj 1"):
        st.session_state.df = df[df["Type"].isin([1])]

    if st.button("obj 2"):
        st.session_state.df = df[df["Type"].isin([2])]

edited_df = st.data_editor(st.session_state["df"])

if st.button("Submit"):
    df = st.session_state["df"]
    only_diff_df =
    changde_df_row = df[df.index.isin(only_diff_df.index)]
    for i in only_diff_df.index:
        changde_df_row = df[df.index.isin([i])]
        st.write("Chanded to ")
    st.session_state["df"] = edited_df

st.experimental_data_editor was deprecated in version 1.23.0. Use st.data_editor instead.

Thanks for your comment. And Fair point. I’ve modified the topic using data_editor. Cheers.