Selectbox does not adapt

I am using the following piece of code:

import streamlit as st
choice = st.selectbox("Choose your Database", ("Default", "Custom Database Link"))
if choice == "Default":
    link = "mongodb://root:blabla/"
else:
    link = st.text_input("Custom Database Link")
st.write(link)

However, this selects "Default" on its own and it does not adapt (immediately) to the userโ€™s choice. Is the structure of this streamlit code wrong?

Hi @vivian1,

Thanks for posting!

What value are you hoping to use as the default? You can pass an index to st.selectbox to specify the default value (check out the st.selectbox doc here).

Iโ€™m not seeing the behavior with the app not updating immediately when the user has selected an option. Your st.write(link) line wonโ€™t necessarily update after the user makes a different selection, because that line appears once in your app. Instead, you could do the following:

if choice == "Default":
    link = "mongodb://root:blabla/"
    st.write(link)
else:
    link = st.text_input("Custom Database Link")
    st.write(link)

Caroline :balloon:

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