Can I add to. a selectbox an "other" option, where the user can add his own answer?

I’d condition a st.text_input to one of the possible options in the st.selectbox, like this:

selectbox

import streamlit as st

# Create selectbox
options = [f"Option #{i}" for i in range(3)] + ["Another option..."]
selection = st.selectbox("Select option", options=options)

# Create text input for user entry
if selection == "Another option...": 
    otherOption = st.text_input("Enter your other option...")

# Just to show the selected option
if selection != "Another option...":
    st.info(f":white_check_mark: The selected option is {selection} ")
else: 
    st.info(f":white_check_mark: The written option is {otherOption} ")
3 Likes