Different selectbox are linked

Consider the following example:

options1 = [1, 2, 3]
options2 = ["foo", "bar"]
option_central = st.selectbox("Which number do you like best?", options1)

"You selected in the central selection: ", option_central

option1_sidebar = st.sidebar.selectbox(
    "Which number do you like best?", options1

"You selected in the sidebar:", option1_sidebar

option2_sidebar = st.sidebar.selectbox(
    "Which number do you like best?", options2

"You selected in the sidebar:", option2_sidebar

When changing option1_sidebar the value rendered for option_central changes as well. It is as if it is somehow related to the variable which holds the list of options. If a different list/variable is used (like in option2_sidebar) the the behavior is aligned better with what I expected. Is it a bug or a feature?

@drorata, this is similar to what I am experiencing, but my use case is somewhat more complicated as I am defining widgets in a for loop: Programmatically Generating Streamlit App

Thanks, @technicalfiddles for linking to your issue, but unfortunately it was not solving my problem. Did it solve yours? If so how exactly, could you please elaborate a little?

This is somehow related to the label. If you change your code so that the strings that refer to options1 are different, this doesnโ€™t happen. For example:

option1_sidebar = st.sidebar.selectbox(
    "Which side number do you like best?", options1
1 Like

Thatโ€™s indeed solving the problem. However, this is a little un-intuitive, isnโ€™t it? Intuitively, the caption of the selection box is meta-data of the box and should not have this side effect. Or do I miss understand something?

Hi All

There is a discussion/ request regarding โ€œconfirmโ€ buttons and forms here that might be relevant for this discussion.