Summary
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!')
else:
st.warning('No selectboxes selected!')
If applicable, please provide the steps we should take to reproduce the bug:
→ State mismatch
- Click on select all
- All checkboxes turn visually active
- Press Do Something
→ Result: Warning that no checkboxes were selected
→ Correct state
- manually check some checkboxes by clicking on them
- checkboxes turn visually active
- 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