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?

Thanks,
Charly

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 DataInput.py file line 246.

Thanks for the help.