-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsync_checklists.py
31 lines (26 loc) · 1.04 KB
/
sync_checklists.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from dash import Dash, dcc, html, Input, Output, State, callback_context
external_stylesheets = ["https://codepen.io/chriddyp/pen/bWLwgP.css"]
app = Dash(__name__, external_stylesheets=external_stylesheets)
options = ["New York City", "Montréal", "San Francisco"]
app.layout = html.Div(
[
dcc.Checklist(["All"], [], id="all-checklist", inline=True),
dcc.Checklist(options, [], id="city-checklist", inline=True),
]
)
@app.callback(
Output("city-checklist", "value"),
Output("all-checklist", "value"),
Input("city-checklist", "value"),
Input("all-checklist", "value"),
)
def sync_checklists(cities_selected, all_selected):
ctx = callback_context
input_id = ctx.triggered[0]["prop_id"].split(".")[0]
if input_id == "city-checklist":
all_selected = ["All"] if set(cities_selected) == set(options) else []
else:
cities_selected = options if all_selected else []
return cities_selected, all_selected
if __name__ == "__main__":
app.run_server(debug=True)