Can I have an optional dropdown? So if a certain value is selected in a dropdown, then a second dropdown appears to drill down further

As stated in the subject, I would like to hide/show the dropdown based on inputs from other objects (say another dropdown). Is this possible?

Hello @filiron,

Welcome to the community!

Yes, this possible. You just need to create a callback from the input of the 1st value to output to the 2nd options.

Hi @jinnzor, thank you for the reply. Can you please point me to which options I need to toggle in the callback? I have searched for it but was not able to find how to show/hide the entire object. Thank you

You have to pass the list of options that you desire back to the options on change of the value of the 1st drop down. You just rebuild it each time, its not about hiding or showing items in it.


You will need to use value from first dropdown to return second dropdown options using callbacks. Something as below:


def update_options(continent,country):
    if continent != [] and country != []:
        dff = df2[df2['continent'].isin(continent)]
        df3 = dff[dff['country'].isin(country)]
    elif continent != [] and country == []:
        df3 = df2[df2['continent'].isin(continent)]
    elif continent == [] and country != []:   
        df3 = df2[df2['country'].isin(country)]    
        df3 = df2.copy()
    return [{'label':x,'value':x} for x in df3.sort_values('language')['language'].unique()]

Thank you both @jinnyzor and @hoatran

1 Like