Hey all,
This is my problem: I have a plot that’s connected to a multi-dropdown. Each selection is a country that is added to the plot.
The thing is, because there’s too many countries, I’d want to have RadioItems options that let you pre-populate the dropdown. Let’s say I want to have the option to prepopulate with countries from Europe. I tried with this:
countries= df[df.continent=='Europe'].country.unique()
options_radio = [{'label': 'European countries', 'value': countries.tolist()}]
options_countries = [{'label': i, 'value': i} for i in df.country.unique()]
html.Div(dcc.RadioItems(id='pre-filter', options=options_radio)),
html.Div('Seleccione países a graficar:'),
html.Div(dcc.Dropdown(id='filter-plot',
options=options_countries,
multi=True
), style={'margin-bottom': 15}),
dcc.Graph(id='plot', style={'margin-top': 35}
)
@app.callback(Output(component_id='filter-plot', component_property='value'),
[Input(component_id='pre-filter', component_property='value')])
def link_radio_dropdown(value):
return value
@app.callback(Output(component_id='plot', component_property='figure'),
[Input(component_id='filter-plot', component_property='value')])
def plot(countries):
etc
return fig
I noticed this only works if the RadioItems component gets a string as value, but when I give it a list, it brings “Invalid argument options[0].value
passed into RadioItems with ID “pre-filter”.”
What can I do? is there any workaround to this?
Thanks!