@jinnyzor: I see that her requirement is more complicated that after choosing value from first filter, it will return another filter based on it. So I did something as below but I didn’t figure out how to disable options after choosing and keep the Checkbox as her example. Can you give me a look and a suggestion. Or can you give us a sample with pattern matching. Thank you.
import dash
import dash_html_components as html
import dash_core_components as dcc
from dash.dependencies import Input, Output
import dash_bootstrap_components as dbc
app = dash.Dash(__name__,external_stylesheets=[dbc.themes.LUX])
app.layout = html.Div([
dbc.Row([
dbc.Col([
dcc.Dropdown(id='main_dropdown',
options=[
{'label': 'Status', 'value': 'Status'},
{'label': 'Tracker', 'value': 'Tracker'},
{'label': 'Priority', 'value': 'Priority'},
],
value='Status',
disabled=False)
],width={'size':3,'offset':0,'order':1}),
dbc.Col([
dbc.Checkbox(label="Status",
value=True,
id="checklist-input",
)
],width={'size':1,'offset':0,'order':1}),
dbc.Col([
html.Div(id='sub_dropdown_1')
],width={'size':3,'offset':0,'order':1})
], className='p-2 align-items-center'),
dbc.Row([
dbc.Col([
html.Div(id='checklist-input-2')
],width={'size':1,'offset':3,'order':1}),
dbc.Col([
html.Div(id='sub_dropdown_2')
],width={'size':3,'offset':0,'order':1})
], className='p-2 align-items-center'),
dbc.Row([
dbc.Col([
html.Div(id='checklist-input-3')
],width={'size':1,'offset':3,'order':1}),
dbc.Col([
html.Div(id='sub_dropdown_3')
],width={'size':3,'offset':0,'order':1})
], className='p-2 align-items-center'),
])
@app.callback(Output('sub_dropdown_1', 'children'),
[Input('checklist-input', 'value')])
def update_options_1(main_dropdown):
if main_dropdown == True:
return html.Div(
dbc.Row([
dcc.Dropdown(
options=[
{'label': 'New', 'value': 'New'},
{'label': 'Confirmed', 'value': 'Confirmed'},
{'label': 'Closed', 'value': 'Closed'},
],
value='New')
])
)
else:
return html.Div()
@app.callback(Output('checklist-input-2', 'children'),
[Input('main_dropdown', 'value')])
def update_options_1(main_dropdown):
if main_dropdown == 'Tracker':
return dbc.Checkbox(label="Tracker",
value=True,
id="checklist-input-2-2",
)
else:
return html.Div()
@app.callback(Output('sub_dropdown_2', 'children'),
[Input('checklist-input-2-2', 'value')])
def update_options_1(main_dropdown):
if main_dropdown == True:
return html.Div(
dbc.Row([
dcc.Dropdown(
options=[
{'label': 'Defect', 'value': 'Defect'},
{'label': 'Feature', 'value': 'Feature'},
{'label': 'Pass', 'value': 'Pass'},
],
value='Pass')
])
)
else:
return html.Div()
@app.callback(Output('checklist-input-3', 'children'),
[Input('main_dropdown', 'value')])
def update_options_1(main_dropdown):
if main_dropdown == 'Priority':
return dbc.Checkbox(label="Priority",
value=True,
id="checklist-input-3-2",
)
else:
return html.Div()
@app.callback(Output('sub_dropdown_3', 'children'),
[Input('checklist-input-3-2', 'value')])
def update_options_1(main_dropdown):
if main_dropdown == True:
return html.Div(
dbc.Row([
dcc.Dropdown(
options=[
{'label': 'Low', 'value': 'Low'},
{'label': 'Normal', 'value': 'Normal'},
{'label': 'High', 'value': 'High'},
],
value='Normal')
])
)
else:
return html.Div()
if __name__ == "__main__":
app.run_server(debug=False,port=1115)