Checkbox state in form


When using checkboxes in a streamlit form, the value of the checkbox does not always match it visual state.

Steps to reproduce

Code snippet:

import streamlit as st

default_checkbox_value = False
if st.button('Select All'):
    default_checkbox_value = True
if st.button('Deselect All'):
    default_checkbox_value = False

checkbox_statusses = []
with st.form(key='data_approval'):
    approve_button = st.form_submit_button(label='Do Something')

    for i in range(5):
        checkbox_statusses.append(st.checkbox('select', key=str(i), value=default_checkbox_value))

if approve_button:
    if any(checkbox_statusses):
        st.header('You selected some checkboxes!')
        st.warning('No selectboxes selected!')

If applicable, please provide the steps we should take to reproduce the bug:

→ State mismatch

  1. Click on select all
  2. All checkboxes turn visually active
  3. Press Do Something

→ Result: Warning that no checkboxes were selected

→ Correct state

  1. manually check some checkboxes by clicking on them
  2. checkboxes turn visually active
  3. Press Do something

→ result as expected, no warning

Expected behavior:

That the Select All button works to activate all checkboxes and so there is no state mismatch.

Actual behavior:

Select All checks the checkboxes, but the state does not represent this.

Is this a regression?

That is, did this use to work the way you expected in the past?
I did not test this before

Debug info

  • Streamlit version: 1.5.1
  • Python version: 3.8
  • Using Conda? PipEnv? PyEnv? Pex? Pycharm venv
  • OS version: macos 10.15.5
  • Browser version: Chrome

Additional information

Also posted on github at: Checkbox state in form · Issue #4457 · streamlit/streamlit · GitHub

Thanks for opening an issue @Thiemo_Seys. I’m closing this one here so we don’t have multiple discussions.