Would like to reset an experimental data editor to the original passed in dataframe. Once edits are made, I want the ability for the user to āabandonā those edits
Iāve tried the steps from here:
if 'user_data' not in st.session_state:
st.session_state['user_data'] = user_data
modified_df = st.experimental_data_editor(st.session_state['user_data'], num_rows='dynamic', key=data_editor_key)
if st.button('Reset Changes'):
st.session_state['user_data'] = user_data
st.experimental_rerun()
You can assign a key to your data editor, then change the key when you want to force Streamlit to create a new, āfreshā one. By using a different key, Streamlit will just āstart overā with the data editor.
Could you not save the original dataset in a different key such as āoriginal_dataā within the session state and if the user abandons the changes then update the editable df with the original_data from the session state?
Are there any memory/performance effects to this approach? i.e., if the user does it alot, or with a large DF, will those old ones hang around in memory?
I canāt say for 100%, but in general widgets have a cleanup process when they are no longer rendered. Hence, Streamlit should discard that widget data associated to the old key when you change it to a new one. You could profile the memory in a test case to be certainā¦