Commit 64fa74d1 authored by Christophe Benz's avatar Christophe Benz

Use placeholder for dropdowns

parent e2a584d5
......@@ -39,15 +39,6 @@ def none_if_empty(val):
return None if val == "" else val
def compute_dept_dropdown_options(reg_code=None):
"""Compute department dropdown option list."""
dep_list = [
{"label": dep[1], "value": dep[0]}
for dep in app_data.compute_dep_list(reg_code)
]
return [{"label": "-- département --", "value": ""}] + dep_list
external_stylesheets = ["https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css"]
server = flask.Flask(__name__)
......@@ -68,12 +59,10 @@ app.layout = html.Div(
children=[
dcc.Dropdown(
id="region",
placeholder="Région...",
options=[
{"label": "-- région --", "value": ""},
*[
{"label": reg[1], "value": reg[0]}
for reg in app_data.reg_list
],
{"label": label, "value": value}
for value, label in app_data.reg_list
],
value="",
),
......@@ -83,24 +72,17 @@ app.layout = html.Div(
className="mb-2",
children=[
dcc.Dropdown(
id="departement",
options=compute_dept_dropdown_options(),
value="",
id="departement", placeholder="Département...", value=""
),
],
),
],
),
dcc.Loading(
id="loading-charts",
html.Div(
className="flex",
children=[
html.Div(
className="flex",
children=[
dcc.Graph(id="bar-chart", className="w-1/2"),
dcc.Graph(id="map", className="w-1/2"),
],
)
dcc.Graph(id="bar-chart", className="w-1/2"),
dcc.Graph(id="map", className="w-1/2"),
],
),
],
......@@ -116,7 +98,11 @@ app.layout = html.Div(
)
def update_dept_dropdown_options(reg_code):
"""Update department list when a region has been chosen."""
options = compute_dept_dropdown_options(reg_code=none_if_empty(reg_code))
reg_code = none_if_empty(reg_code)
options = [
{"label": label, "value": value}
for value, label in app_data.compute_dep_list(reg_code)
]
value = ""
return options, value
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment