Hi There! This is an interesting question.
The closest I believe we could get is something like the below toy app. I have three callbacks pointing to the disabled
property of each of the three dropdowns. If the total number of options picked in the three callbacks reaches 5, I set all the dropdowns to disabled.
The problem is once set to disabled, the dropdown is ENTIRELY disabled. I could imagine a new component property being potentially useful: Something that disables the selection of new options but still allows a user to deselect.
I’d be interested to see if the community has any other thoughts on a potential workaround.
Also cc @chriddyp
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import json
app = dash.Dash()
app.layout = html.Div([
dcc.Dropdown(
options=[
{'label': 'one', 'value': 'one'},
{'label': 'two', 'value': 'two'},
{'label': 'three', 'value': 'three'}
],
multi=True,
id='dropdown-one',
value=['one']
),
dcc.Dropdown(
options=[
{'label': 'four', 'value': 'four'},
{'label': 'five', 'value': 'five'},
{'label': 'six', 'value': 'six'}
],
multi=True,
id='dropdown-two',
value=['six']
),
dcc.Dropdown(
options=[
{'label': 'seven', 'value': 'seven'},
{'label': 'eight', 'value': 'eight'},
{'label': 'nine', 'value': 'nine'}
],
multi=True,
id='dropdown-three',
value=['eight']
),
html.Div(id='results')
])
@app.callback(
Output('results', 'children'),
[Input('dropdown-one', 'value'), Input('dropdown-two', 'value'),
Input('dropdown-three', 'value')]
)
def display_results(val1, val2, val3):
full_list = val1+val2+val3
return json.dumps(full_list)
@app.callback(
Output('dropdown-one', 'disabled'),
[Input('dropdown-one', 'value'), Input('dropdown-two', 'value'),
Input('dropdown-three', 'value')]
)
def disable_dropdown_one(val1, val2, val3):
full_list = val1+val2+val3
if len(full_list) >= 5:
return True
else:
return False
@app.callback(
Output('dropdown-two', 'disabled'),
[Input('dropdown-one', 'value'), Input('dropdown-two', 'value'),
Input('dropdown-three', 'value')]
)
def disable_dropdown_two(val1, val2, val3):
full_list = val1+val2+val3
if len(full_list) >= 5:
return True
else:
return False
@app.callback(
Output('dropdown-three', 'disabled'),
[Input('dropdown-one', 'value'), Input('dropdown-two', 'value'),
Input('dropdown-three', 'value')]
)
def disable_dropdown_three(val1, val2, val3):
full_list = val1+val2+val3
if len(full_list) >= 5:
return True
else:
return False
if __name__ == '__main__':
app.run_server()