Hello everyone!
In the code below I have a dropdown that allows you to generate a specified number of dropdown. I would like to reset the options of the drop-downs form another callback and could not figure out how to do so.
I appreciate everyone’s time
from dash import Dash, html, dcc, callback, Input, Output, State, ctx, no_update, ALL, callback_context, MATCH
import dash_mantine_components as dmc
app = Dash(__name__)
app.layout = html.Div(
children = [
dmc.Select(
id= 'select-num-dropdowns',
label= 'Select Number of Dropdowns',
data= ['1', '2', '3', '4']
),
html.Div(id='dropdown-group'),
]
)
@app.callback(
Output("dropdown-group", "children"),
Input("select-num-dropdowns","value"),
prevent_initial_call=True,
)
def make_dropdowns(num):
num = int(num)
drop_downs = []
for idx, value in enumerate(range(0, num)):
option = ['one', 'two', 'three', 'four']
drop_downs.append(
dmc.Select(
id={'type': 'dynamic-selects','index': idx+1},
label= f'Dropdowns {option[idx]}',
data=option,
value = option[idx]
)
)
return dmc.Group(drop_downs, grow=True)
@app.callback(
Output({'type':'dynamic-selects', 'index': ALL}, 'data'),
Input({'type':'dynamic-selects', 'index': ALL}, 'value'),
Input("select-num-dropdowns","value")
)
def update_dynamic_dropdowns(dropdowns, num):
outputs = [['bananas', 'apples', 'oranges'] for n in range(0, int(num)) ]
print('input list : ', ctx.inputs_list)
print('input list : ', ctx.outputs_list)
return outputs
if __name__ == '__main__':
app.run(debug=True)