Clear st.data_editor after some task

I’m creating a page with a st.data_editor to receive user data and save it to a database. It works perfectly, but how do I reset data_editor after saving the data without asking the user to click on page link on the side bar again?

1 Like

Change the key of the data editor.

import uuid

# Define a variable as a key of the data editor.
if 'dek' not in st.session_state:
    st.session_state.dek = str(uuid.uuid4())

def update(edf):
    # save_to_db(edf)

    # Change the key of the data editor to start over.
    st.session_state.dek = str(uuid.uuid4())

edf = st.data_editor(df, key=st.session_state.dek)
st.button('Save', on_click=update, args=(edf,))