How to manually clear values in the widgets.

I have created a manual entry form for my organization using the st.form method that clears the entries after submission. I later moved the logic outside the form because, widget to widget interactivity is required and is not possible to achieve dynamically in form method. Is there any way to clear the values in the widgets after submission. I tried to access the keys and set it to None, but I’m getting the following error: streamlit.errors.StreamlitAPIException: st.session_state.start_date_widget cannot be modified after the widget with key start_date_widget is instantiated. I would to know if there is any workaround because manually clearing the inputs one by one in the widgets is problematic.

Hi! I usually use the callbacks to do this kind of thing: try reset the sessions state variables into the on_change/on_ function and it should work

1 Like

Streamlit raises the error because widget values in st.session_state cannot be directly set after the widget has been created.

Thank you so much @Marco5 it worked.

1 Like