How to reset checkbox

My target:

  1. Enter a key in text box, the App will run a query and return a list of options.
  2. For each option, display a checkbox and check it by default.
  3. The options from step 1 are likely to be the same among different runs but with small difference.
  4. I don’t want to use multiselect drop down here.

The issue:

  1. If I uncheck a checkbox, the state will be memorized even if the checkbox is regenerated.
  2. Yes I tried to give the a unique id for each checkbox but it will keep resetting every checkbox.

A example code:

import streamlit as st
import numpy as np

def main():
    case_id = st.text_input("Please enter an ID")
    if case_id:
        options = sorted(np.random.choice([1,2,3,4,5], 4, replace=False))
        pathways_bool = [st.checkbox(str(_x),True) for _x in options]

if __name__ == "__main__":

Thanks for your help!

Hey @Bo9562,

Welcome to the Streamlit Community! I’m afraid I don’t quite understand the problem you have here (sorry about that!). Streamlit is designed so that when you check or uncheck a box, that would usually feed back into your script somewhere and dynamically change something on the web page. For example, if you unchecked the option ‘2’, the script would re run and then display/not-display something that was linked to that ‘2’ checkbox.

When the script reruns, technically the checkboxes are regenerated then, and if it never remembers the users selection, then nothing will happen on the page.

Why are you looking for this functionality? A more specific example in this case may help us identify a different widget that might be more suited to your needs!

Hope this helped!
Happy Streamlit-ing!