I have a few dropdowns dependent on radio items. What is allowed to populate in the dropdowns depend on the radio items. However when I change the radio items, back and forth, it doesn’t reset the dropdown selections. Here is a simple example of what I’m attempting that’s not working. Didn’t include the layout part but the df is in a dcc.Store component, the drops are in dcc.Dropdown and the radio is a dbc.RadioItems.
df = pd.DataFrame({'A': [1, 2, 3, 4, 5],
'B': [6, 7, 8, 9, 10],
'C': [11, 12, 13, 14, 15],
'D': [16, 17, 18, 19, 20]}
app.callback(
Output('drop-2', 'options'),
Output('drop-3', 'options'),
Output('drop-1', 'value'),
Output('drop-2', 'value'),
Input('drop-1', 'value'),
Input('drop-2', 'value'),
Input('radio', 'value'),
State('store', 'data')
def update(value1, value2, radio, data):
df = pd.DataFrame(data['df'])
if radio == 'foo':
if not value1:
return [], [], '', '', ''
elif value1:
if not value2:
return df['A'], [], value1, '', ''
elif value2:
return df['A'], df['B'], value1, value2
elif radio == 'goo':
if not value1:
return [], [], [], '', '', ''
elif value1:
if not value2:
if not value2:
return df['C'], [], [], value1, '', ''
elif value2:
return df['C'], df['D'], value1, value2
With this code I can get the dropdowns to reset when changing previous drop downs but when I change radios back and forth they aren’t clearing. I’m sure it’s a simple fix but I just can’t see it.