St.data_editor don't update data

Hello !, i am working on a data app where i would put a “data entery” module using st.data_edito.
I have noticed that if we filter the main df (for better target what we need to enter) the data_editor doeasnt update. here is an example code to be clearer:

import streamlit as st
import pandas as pd

data = {
    "id": [1, 2, 3],
    "date": ["2023-01-01", "2023-01-02", "2023-01-03"],
    "state": ["alive", "dead", "dead"],
    }
df = pd.DataFrame(data)
df['date'] = pd.to_datetime(df['date'])

id_lot_ext_to_check = st.selectbox("Select ID", options=df["id"].tolist(), index=None, placeholder="Select ID", label_visibility="collapsed")
    
filtered_df = df[df["id"] == id_lot_ext_to_check]

if not filtered_df.empty:
    with st.form(key="sauv_form"):
        edited_df = st.data_editor(filtered_df, num_rows="dynamic", use_container_width=True, hide_index=True,
            column_config={
                "date": st.column_config.DateColumn("date", format="YYYY/MM/DD"),
                "state": st.column_config.SelectboxColumn("state", width="medium", options = ["alive", "dead"])
            },
            )

        done_but = st.form_submit_button('print_df')

    if done_but:
        print(edited_df)

here even after modifying edited_df (in the user ui) the filtered_df never update.

But if, in the data_editor we put directly the original df ( in this case “df”) the data_editor updates correctly

Can anyone help me please, am i doing some logic issue ?

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