Disable selectbox if a value is choosen in an other selectbox

Hello every one ,

I am new around and i am trying to POC a small web App with streamlit using it on the snowflake environnement so this means streamlit 1.26 version.
When it comes to create selectbox it worked well but then i wanted to disable the other selectbox because value in one is choosen , i can’t do it because i can’t call again the same selectbox.
I am using a function here but i am opened to new idea .
Here is the part that doesn’t work and my error message :

#select a checkbox to print a selectbox
#initialisation of the variables to false
disabled_select_restaurantuniqueid = False
disabled_select_BK_number = False
disabled_select_nomdurestaurant = False
select_restaurantuniqueid = "" 
select_BK_number = ""
select_nomdurestaurant = ""

def selectbox(disabled_select_restaurantuniqueid,disabled_select_BK_number,disabled_select_nomdurestaurant) :
    select_restaurantuniqueid = st.selectbox('RESTAURANTUNIQUEID',options = list_restaurantuniqueid,index = 0 ,disabled = disabled_select_restaurantuniqueid)
    select_BK_number = st.selectbox('BK',list_BK_number,index = 0,disabled = disabled_select_BK_number )
    select_nomdurestaurant = st.selectbox('NOMDURESTAURANT',list_nomdurestaurant,index = 0,disabled = disabled_select_nomdurestaurant)
    return select_restaurantuniqueid,select_BK_number,select_nomdurestaurant

select_restaurantuniqueid = "" 
select_BK_number = ""
select_nomdurestaurant = ""

selectbox(disabled_select_restaurantuniqueid,disabled_select_BK_number,disabled_select_nomdurestaurant)
if select_restaurantuniqueid != list_restaurantuniqueid[0]: 
    disabled_select_BK_number = True
    disabled_select_nomdurestaurant = True
if select_BK_number!= list_BK_number[0]: 
    disabled_select_restaurantuniqueid = True
    disabled_select_nomdurestaurant = True
if select_restaurantuniqueid != list_nomdurestaurant[0]: 
    disabled_select_BK_number = True
    disabled_select_restaurantuniqueid = True
selectbox(disabled_select_restaurantuniqueid,disabled_select_BK_number,disabled_select_nomdurestaurant)

here is my error message : DuplicateWidgetID: There are multiple identical st.selectbox widgets with the same generated key.

When a widget is created, it’s assigned an internal key based on its structure. Multiple widgets with an identical structure will result in the same internal key, which causes this error.

Here is a screen of the frondend :
image
so i would like the other selectbox than the one selected to be disable , in this case the 2nd and 3rd one

Thanks for your time and ideas :slight_smile:

Zuwhity

in the main idea, I think you can try to use st.session_state rather than simply put every variables out there.

feel free to try this:


if 'true_or_false' not in st.session_state:
    st.session_state['true_or_false'] = True
    
st.session_state['true_or_false'] = st.selectbox('box1', [True, False] , index = 0)
sb2 = st.selectbox(
    'box2', ['aaa', 'bbb'], index = 1, disabled=not st.session_state['true_or_false']
    )