Depdendant Selectbox

Dear Community,

Recently I trying to build an app with a dataframe which has more than 15000 rows and 75 columns.
Looks like this:

From this dataset, I want to let user select Manufacturer first, then the model Number to further store and display related values for next steps. Something like this:

Please help!!

Hi,

You can modify the choices of the first select box to display “Select” by default and only render second select box if the first value is not “Select”.

Let me know you need any further help

Thanks,
Akshansh

Dear Akshan,

What I need is a dependent dropdown where the logic will be like this:

Can you please give a few lines of code to implement this using streamlit please?

Hi

Try this:

import streamlit as st

dummy_data = {
    'Man1':['1','111','1111'],
    'Man2':['2','222','22222'],
    'Man3':['3','333','33333'],
}

if __name__ == "__main__":
    # adding "select" as the first and default choice
    manufacturer = st.selectbox('Select Manufacturer', options=['select']+list(dummy_data.keys()))
    # display selectbox 2 if manufacturer is not "select"
    if manufacturer != 'select':
        model_number = st.selectbox('Select Model Number', options=dummy_data[manufacturer])
    if st.button('Submit'):
        st.write('You selected ' + manufacturer + ' ' + model_number)

Animation2

Thanks,
Akshansh

Dear @akshanshkmr ,

Thanks for the code. but the problem is I need streamlit to read the below dataset and based on “Manufacturer” and “Model Number” selection, the code will give the rest of the values as output to store in a dict or another DF.