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?