St.data_editor does not update

When running my app locally with Streamlit version 1.31.0, I’m encountering an issue with st.data_editor. I’m aiming to create a dynamic behavior where if a user changes a parameter called “number of arrivals,” new rows are added to the data editor for the user to input new data.

Here’s the code I’ve written:

with arrival_data:
data_dict = {“Number of (aggregated) vehicles”: default_aggregated, “Arrival time”: default_arrival_time, “Stay length”: default_length_stay}
if “df” not in st.session_state:
st.session_state.df = pd.DataFrame(data_dict, index=range(self.num_arrival))
elif len(st.session_state.df) != self.num_arrival:
st.session_state.df = pd.DataFrame(data_dict, index=range(self.num_arrival))
st.data_editor(st.session_state.df, key=f’editor_{i}_{j}')

However, it’s not working as expected. When I add a new arrival row, all the entered data revert to the defaults instead of retaining the previous data before adding a new row to the dataframe. How can I fix this?

Hi @Fatemeh_Norouzi! :wave:

Would it be possible for you to share your repo, please?


Hi @Charly_Wargnier ,
Yes, this is the repo: Fatemeh Norouzi / streamlit data editor · GitLab.
The main part of the code related to my problem is in the src folder in file line 246.

Thanks for the help.