I think this is a bug in Dash Dropdowns. Please read below.
I want to create a dropdown where the options get dynamically updated when the user starts typing, AND the options are Dash HTML components.
Following the example in the Dynamic Options section I was able to make dynamic options work. However, whenever I make the labels HTML components instead of plain strings, dynamic options functionality stops working.
I believe this to be easily reproducible. Just use this from the documentation:
@app.callback(
Output("my-dynamic-dropdown", "options"),
Input("my-dynamic-dropdown", "search_value")
)
def update_options(search_value):
if not search_value:
raise PreventUpdate
options = get_html_component_options(search_value)
return options
For simplicity, get_html_component_options() would return something like this as an example:
Maybe I should have said that explicitly, but the whole point is that options should be updated as the user type, on the fly. No button needs to be pressed to update the options. This happens without problems when the option labels are plain strings (and this is the case with the documentation example.) But when the labels are HTML components, this update-on-the-fly stops working and the search value gets erased when you un-focus the dropdown.