St.selectbox aftect another without submitting a form

Hi, I would like to have two st.selectbox on a page.

In the st.selectbox1 are several options.
After choosing one option in the st.selectbox1 should be the options for st.selectbox2 dynamically filtered.

I do NOT want to use a form / submitt button.

Options for st.selectbox1 are: ‘none’, a and b.
if st.selectbox1==‘none’, then st.selectbox2 - no options.
if st.selectbox1==a, then st.selectbox2 - red, white.
if st.selectbox1==b, then st.selectbox2 - black, yellow.

Is there any way, how to “dynamically” filter a selectbox options?

Hi @pit9921

Thanks for your question. You can use conditional statements to display diferent selectbox options.

Would the following code snippet perform the intended feature for your app?

import streamlit as st

selectbox1_options = ['none', 'a', 'b']
selectbox1_value = st.selectbox('Selectbox 1', selectbox1_options)

selectbox2_options = []
if selectbox1_value == 'none':
    selectbox2_options = []
elif selectbox1_value == 'a':
    selectbox2_options = ['red', 'white']
elif selectbox1_value == 'b':
    selectbox2_options = ['black', 'yellow']

selectbox2_value = st.selectbox('Selectbox 2', selectbox2_options)

Hope this helps!

Best regards,