[Python] Streamlit: Manually setting Selectbox and Date_Input to values

Discussão em 'Python' iniciado por Stack, Agosto 26, 2025.

  1. Stack

    Stack Membro Participativo

    I'm building an app that, on default, sets date_input and selectbox options

    dateoption = st.sidebar.date_input("Select Date", value=get_previous_business_day(dt.date.today()))
    nameoption = st.sidebar.selectbox(f"Select from {name_count} names", individual_names.NAME.values.tolist(), index=None, placeholder="Name")


    The user can manually select a date and a name from the options.

    I now have added functionality where the app's link can be embedded with parameters, so the dateoption and nameoption can be prefilled. However, I am struggling with how I can force select the two variables. This is what I'm trying:

    params = st.query_params.to_dict()

    if 'name' in params:
    nameoption = params['name']
    # This did not work, and I also tried selecting the value of the index to place as the option but that just created another nameoption selectbox right below the actual one
    #st.session_state.nameoption = individual_names.NAME.values.tolist().index(params['name'])
    if 'date' in params:
    # This doesn't change the selection
    dateoption = datetime.strptime(params['date'], '%Y%m%d').date()


    How can I set the nameoption and dateoption fields equal to what the parameters state?

    Continue reading...

Compartilhe esta Página