Hello, I’m trying to set up a series of paired dropdown selectors, where choosing an option on dropdown A populates options on the paired dropdown B depending on what was selected. The issue that I am having is that the callback on the second pair erases the selection from the first one.
I have slimmed the code down somewhat for this example, but the issue is seen if you select something in the first dropdown (option1), then select something from the second dropdown (option2). This appears to be tied to the callback. I don’t see anything in what I’m doing with the callback that should affect the first dropdown. Any advice/hints/solutions would be greatly appreciated as I have been beating my head against the wall on this for a while.
Thanks.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
app = dash.Dash()
mriIndexDict = {'option1' : ['a', 'b'],
'option2' : ['c', 'd', 'e']}
app.layout = html.Div([
html.Div(children='Select data to display'),
# Select here first
dcc.Dropdown(
id='axis0-category',
options=[{'label' : x, 'value' : x} for x in sorted(mriIndexDict)]
),
# Then select here, and it clears the first dropdown.
dcc.Dropdown(
id='axis1-category',
options=[{'label' : x, 'value' : x} for x in sorted(mriIndexDict)]
),
dcc.Dropdown(
id='axis1-subcategory',
options=[{'label' : x, 'value' : x} for x in sorted(mriIndexDict)])
])
@app.callback(Output('axis1-subcategory','options'),
[Input('axis1-category', 'value')])
def updateAxis1Subcategory(axisCat):
whichID = 'axis1-subcategory'
if not axisCat:
axisCat = 'option1'
return [{'label' : x, 'value' : x} for x in mriIndexDict[axisCat]]
if __name__ == '__main__':
app.run_server(debug=False)