Reset checkboxes after submit is clicked

Hi,
I have several checkboxes. After i click submit i´d like to reset the checkboxes, as new data is shown, but in my case the checkboxes i chose stay clicked. How can i reset them?
kind regards

Hey @fipsi,

First, welcome to the Streamlit Community! :partying_face: :partying_face: :partying_face: :tada: :tada:

The easiest solution is to put your checkboxes in a form and use the clear_on_submit parameter, that way when anyone presses the corresponding st.form_submit_button the widgets will get cleared!

form = st.form("checkboxes", clear_on_submit = True)
with form:
    check_1 = st.checkbox("Click here")
    check_2 = st.checkbox("Another check")

submit = form.form_submit_button("Submit your answers")

Happy Streamlit-ing!
Marisa

1 Like

This just saved me. I have been hitting my head on a wall of checkboxes for hours!!

Thanks!!!

Here’s my code for anyone who comes after:

form = st.sidebar.form("checkboxes", clear_on_submit=True)
with form:
    cols_boxes = form.columns(5), form.columns(5), form.columns(5)

    boxes = [
        [
            cols_boxes[i][(j % 3) + 1].checkbox(
                f"r{i}:c{j%3}", key=f"{i}/{j}", value=False
            )
            for j in range(i * 3, (i + 1) * 3)
        ]
        for i in range(3)
    ]

form.form_submit_button("Play Move")
st.write(boxes)

It looks like this:

image

1 Like

Hey @Outsiders17711,

Glad this was helpful! :star_struck:

Happy Streamlit-ing!
Marisa

1 Like