The searchable feature in the dropdown component is awesome yet it requires that all options be pre-specified. That is, the dropdown options cannot be populated via "external" search. Normally this would never be an issue but if one was populating the dropdown with results from an external database, there is no callback to effectively accommodate this. An example:
@app.callback(
Output('stock-ticker-input', 'options'), # dcc.Dropdown
[Input('add-results-button', 'n_clicks')],
[State('keyword', 'value'), # (dcc.Input)
State('stock-ticker-input', 'options')])
def create_dropdown(n_clicks, keyword, options):
list = []
if n_clicks > 0:
list.extend(options)
results = pd.DataFrame(ts.get_symbol_search('{}'.format(keyword))[0][['2. name', '1. symbol']])
results.columns = ['label', 'value']
list.extend(results.to_dict('rows'))
return list
where ts.get_symbol_search(...) is an API call to the external database. You can see from this example that I am required to make the search using text input and button where results from the search are manually entered into the dropdown to be searched again.
I am suggesting a revision so that the above could look like the following:
@app.callback(
Output('stock-ticker-input', 'options'), # dcc.Dropdown
[Input('stock-ticker-input', 'search_value')],)
def create_dropdown(keyword, options):
results = pd.DataFrame(ts.get_symbol_search('{}'.format(keyword))[0][['2. name', '1. symbol']])
results.columns = ['label', 'value']
return results.to_dict('rows')
Notice that once an option is selected to assume the 'value' property of the dropdown component and the 'search-value' == None, the 'option' is no longer available to the dropdown component thus sustaining the 'value' of a selection becomes questionable.