I ran into an interesting issue this evening, I figured I would share on here in case anyone else observes the same behavior and is looking for a solution.
I had a case where I was iterating through a list and creating a checkbox for each item in the list. Initially, I was observing that clicking any checkbox had the effect of clicking every checkbox.
import streamlit as st
to_be_deleted = set()
for i in range(10):
delete = st.checkbox(f'delete?', False)
if delete:
to_be_deleted.add(i)
st.write(f'to be deleted: {to_be_deleted}')
However, if you change the string in the checkbox to be unique, the observed behavior is as expected.
import streamlit as st
to_be_deleted = set()
for i in range(10):
delete = st.checkbox(f'delete {i}?', False)
if delete:
to_be_deleted.add(i)
st.write(f'to be deleted: {to_be_deleted}')
Lesson learned? Donât use multiple checkboxes with the same name!