Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Christophe Benz
observatoire-dash
Commits
64fa74d1
Commit
64fa74d1
authored
Jan 13, 2020
by
Christophe Benz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use placeholder for dropdowns
parent
e2a584d5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
27 deletions
+13
-27
app.py
app.py
+13
-27
No files found.
app.py
View file @
64fa74d1
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment