Im building a plotly Dash dcc.dropdown
list dynamically using :
def BuildOptions(DataFrameSeries, AddAll):
OptionList = [{'label': i, 'value': i} for i in DataFrameSeries.unique()]
if AddAll == 1:
OptionList.insert(0,{'label': 'All', 'value': 'All'})
return OptionList
it uses unique values in a df
series, and inserts 'All' into the options list. I now want to Set the (default) value to 'All' if it exists or the [0] item in the list of K/V pairs.
html.Div([
dcc.Dropdown(
id='Prov_DD',
options=BuildOptions(data.TASKPROVINCE,1),
# value=data.TASKPROVINCE[0],
# value=dcc.Dropdown.value[0],
value='All' # this works for those list that have 'All'
# but I want [0] item
multi=True
)],className='two columns'
),
Any way of setting the dcc
drop down to a certain item in the options list of key value pairs by index?
dcc. Dropdown is a component for rendering a user-expandable dropdown.
It is possible for a callback to insert new Dash components into a Dash app's layout. If these new components are themselves the inputs to other callback functions, then their appearance in the Dash app's layout will trigger those callback functions to be executed.
Yes. Plotly's Dash analytics application framework is also free and open-source software, licensed under the MIT license.
You should define an options_array. Then use that array to populate the dropdown options and value parameters. Once the array is defined you can select a default value by index from the pre-defined array (options_array).
options_array = BuildOptions(data.TASKPROVINCE,1)
html.Div([
dcc.Dropdown(
id='Prov_DD',
options=options_array,
value=options_array[0],
multi=True)
],
className='two columns'
),
You won't be able to grab a value from dcc.Dropdown(options=...), because it's not actually instantiated yet.
Plus, at this time I think the only other way to pragmatically update dcc.Dropdown is by using callbacks.
Just define the array first.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With