Learn how to use Dash Bio for next-gen sequencing & quality control. 🧬Register for the Oct 27 webinar.

Replace empty value in dropdown

Hey there,

I have a multi drop-down that I want to display a default value if its blank:

(dcc.Dropdown(id='dropdown',clearable=False,
 options=[{'label':i,'value':i} for i in areas],
 value=['All'],
 multi=True))

I tried to implement a callback, but this obviously has the same input and output which isn’t correct.

@app.callback(Output('dropdown','value'),
              [Input('dropdown','value')])   
def refresh_dropdown(x):
    
        if x == ['']:
            return ['All']
        else:
            return country

Any ideas how to handle this, I can set up the function that uses the dropdown as an input to use all but would like the user to see that what is being selected.

thanks

I would suggest to set the placeholder as “All” and you would then catch when the value is None or empty list and interpret it as “All”.

Hey Renaud, that’s my current solution, I was just wondering if its possible to enter a value into a multi drop down, so the user

I was thinking perhaps having a hidden dropdown but that mirrors if not blank and inputs when blank but that creates an undesired loop.