would st.form work for u? There’s a parameter called clear_on_submit that you can set to True so that it clears all the selectboxes.
st.write("Inside the form")
slider_val = st.slider("Form slider")
checkbox_val = st.checkbox("Form checkbox")
# Every form must have a submit button.
submitted = st.form_submit_button("Submit")
st.write("slider", slider_val, "checkbox", checkbox_val)
st.write("Outside the form")
i have a situation like 2 selectboxes, 1 with regions and another 1 one with countries. how to write the session state for both selectboxes such that when region APAC is selected, countries related to APAC region only to be visible as option and vice versa.
No need to put them in a form or have callbacks. Simply have the Regions and Countries selection code blocks following each other. Filter the countries based on the region before handing it to the Countries selection. Whenever a region is selected, Streamlit will rerun preserving the selected region, then you can region-filter the countries list to pass to the Countries selection.
Thanks for your time, i dont want to keep region as a parent always. client expecting region and country both as individual. your current flow region->country->city. what if i want to select the country directly
Are your checkboxes inside a form? If so, then it isn’t possible to do this dynamically without a rerun, and you can’t do a rerun in a callback, so that’ll need to be done based on the value of another state variable outside the form, and this you can set in the callback.
@asehmi Both Selectbox and checkbox are not inside form. With your help, i created two selectboxes for region and country. Parent 1st is Region, once Region selected, 2nd Country confined to region was given as option for selectbox 2. now once i selected options from selectbox2. i want to check and uncheck the checkbox as when i change the options of 2nd select box.