出典:公式リファレンスから
入力項目をwithでくくり、clear_on_submit をTrueにすると、submitボタンが押されると同時に入力ボックスをクリアできる。変数は維持されている。
■st.form
Create a form that batches elements together with a "Submit" button.
A form is a container that visually groups other elements and widgets together, and contains a Submit button. When the form's Submit button is pressed, all widget values inside the form will be sent to Streamlit in a batch.
To add elements to a form object, you can use "with" notation (preferred) or just call methods directly on the form. See examples below.
●Forms have a few constraints:
Every form must contain a st.form_submit_button.
st.button and st.download_button cannot be added to a form.
Forms can appear anywhere in your app (sidebar, columns, etc), but they cannot be embedded inside other forms.
Within a form, the only widget that can have a callback function is st.form_submit_button.
Function signature[source]
st.form(key, clear_on_submit=False)
■Parameters
・key (str)
A string that identifies the form. Each form must have its own key. (This key is not displayed to the user in the interface.)
・clear_on_submit (bool)
If True, all widgets inside the form will be reset to their default values after the user presses the Submit button. Defaults to False. (Note that Custom Components are unaffected by this flag, and will not be reset to their defaults on form submission.)