How to clear data_editor after data is saved in database?

Hello,

I am using the following code in my Streamlit App.
I want the user to input some data in a data_editor. Then, once the Submit button is clicked, the data should be saved to the database, and the data_editor should be cleared.
Here is my code :

def update():
    # Change the key of the data editor to start over.
    st.session_state['input_data'] = str(uuid.uuid4())

new_data = pd.DataFrame(columns=df.columns)

 # Render the data editor with the current key
st.session_state['edf'] =st.data_editor(new_data,
                        hide_index=True,
                        column_config=column_configuration,
                        num_rows="dynamic",
                        key='input_data',
                        use_container_width=True)

# Retrieve added data
added_rows_df=pd.DataFrame(st.session_state['input_data']['added_rows'])


if st.button("Submit new data", type='primary', use_container_width=True, on_click=update) :
    if not added_rows_df.empty :      
        # save_to_db
        dbc = DBConnector()
        dbc.saveData(df=added_rows_df, tablename='prediction') 

This gives the following error message :
StreamlitAPIException : Values for st.button, st.download_button, st.file_uploader, st.data_editor, st.chat_input, and st.form cannot be set using st.session_state.

Many thanks for your help.

Olá, utiliza o comando “clear_on_submit” antes do botão “Salvar”
with st.form(key=“include_grupo_form”, clear_on_submit=True):

Hi,

Thank you for your help. I wanted to use st.data_editor which does not have this clear_on_submit option.
However, I can use st.form as well