Using Bootstrap Dropdown Menu like DCC with default value

Hi-

I would ideally like to do something like:

 dbc.DropdownMenu(label="Menu",
                              value='First', children=[ dbc.DropdownMenuItem("First")])

So that my call back hits ‘value’ as the default input to a callback when my app loads (which is how the dcc dropdown component works). Given that there is no ‘value’ parameter, is this not possible? Or am
I missing something?

Thank you!!

Hey @slevin88

There was a similar question asked on the dash-bootstrap-components repo the other day. I’ll let you check that out for the full details, but in brief it’s possible to use each DropdownMenuItem as a button, and create a callback that takes the n_clicks prop of each one as an input. Though you can’t specify an initial value, you could add some logic to your callback that does something specific if no buttons have been clicked yet, which would achieve the same outcome.

Check out the FAQs on the Dash docs too, specifically the question “How do I determine which Input has changed?”. It has a nice example on determining which button was clicked (if any) using the new dash.callback_content feature.

That being said, I think DropdownMenu is really best suited to navigation type tasks, and if you want to have a component for selecting from different options as an input, dcc.Dropdown may be a better choice. Certainly your callbacks will be simpler. But I shall leave that decision with you :slight_smile: