Is it possible to not show a default option for input widgets?

Hi, I’m new to Streamlit (it’s great!) and am using it for building annotation apps.

To avoid bias, it’s critical for me not to display any default option for the multiple choice questions. I haven’t found any way to do that for either selectboxs/radio buttons/select sliders. There are some workarounds such as adding a filler option for selectboxs but they’re pretty ugly.

Is there any css hack to change the display and avoid highlighting the default option? Any other solution that I missed?

Thanks!

2 Likes

Hi @lilache , is this what you are looking for?

lst = ("", "A", "B", "C")
unme1 = st.selectbox("Choose a user", lst, index=2)
unme2 = st.radio("Choose an option:", lst, index=3)

You can change the index to set your default option

Cheers

@Shawn_Pereira , thanks, this is pretty much what I do now, but it’s not very pretty, especially for radio buttons.
I’m looking for a way to display only the actual options (“Yes” and “No” in my case) but make the default option appear just as the others.

you can decide it by making correct list, such as:

choose = st.selectbox("choose one option", ("A", "B","C"))

as above, A will be default option for choose, if you like, you can make B or C to the first option like this:

choose = st.selectbox("choose one option", ("B", "A","C"))
choose = st.selectbox("choose one option", ("C", "B","A"))

A bit tricky, but it works!

    if 'A' not in st.session_state:
        st.session_state.A = 0
        st.session_state.B = 0
        st.session_state.C = 0
    def ChangeA():
        st.session_state.A,st.session_state.B,st.session_state.C = 1,0,0
    def ChangeB():
        st.session_state.A,st.session_state.B,st.session_state.C = 0,1,0
    def ChangeC():
        st.session_state.A,st.session_state.B,st.session_state.C = 0,0,1
    
    col1, col2, col3, _ = st.columns([1,1,1,8])
    with col1:
        a = st.checkbox('A', value = st.session_state.A, on_change = ChangeA)
    with col2:
        b = st.checkbox('B', value = st.session_state.B, on_change = ChangeB)
    with col3:
        c = st.checkbox('C', value = st.session_state.C, on_change = ChangeC)
        
    st.session_state.A
    st.session_state.B
    st.session_state.C

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.