Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
pmall
app_OP
Commits
58792d77
Commit
58792d77
authored
Sep 21, 2020
by
Samuël Weber
Browse files
better sidebar logic
parent
0390a050
Changes
2
Hide whitespace changes
Inline
Side-by-side
apps/app_results.py
View file @
58792d77
# -*- coding: utf-8 -*-
# import dash
import
collections
from
dash.dependencies
import
Input
,
Output
,
State
import
dash_core_components
as
dcc
import
dash_html_components
as
html
...
...
@@ -54,20 +55,22 @@ BUTTONS = [
"pmf_unc"
,
"pmf_sr"
,
"op_beta"
,
"op_obsvsmodel"
,
"op_contrib"
,
"op_contrib_ts"
,
"help"
,
]
COMPONENTS
=
{
"rd_ts"
:
ac
.
get_rawdata_timeserie_component
(),
"rd_monthly"
:
ac
.
get_rawdata_monthly_component
(),
"rd_seasonal"
:
ac
.
get_rawdata_seasonal_component
(),
"pmf_profiles"
:
ac
.
get_profile_component
(),
"pmf_deltatool"
:
ac
.
get_deltatool_component
(),
"pmf_unc"
:
ac
.
get_uncertainty_component
(),
"pmf_sr"
:
ac
.
get_specie_repartition_component
(),
"op_beta"
:
ac
.
get_op_beta_component
(),
"op_obsvsmodel"
:
ac
.
get_op_obs_vs_model_component
(),
"op_contrib"
:
ac
.
get_op_contribution_component
(),
"op_contrib_ts"
:
ac
.
get_op_contribution_ts_component
(),
"help"
:
ac
.
get_about_app_results_component
(),
}
COMPONENTS
=
collections
.
OrderedDict
({})
COMPONENTS
[
"rd_ts"
]
=
ac
.
get_rawdata_timeserie_component
()
COMPONENTS
[
"rd_monthly"
]
=
ac
.
get_rawdata_monthly_component
()
COMPONENTS
[
"rd_seasonal"
]
=
ac
.
get_rawdata_seasonal_component
()
COMPONENTS
[
"pmf_profiles"
]
=
ac
.
get_profile_component
()
COMPONENTS
[
"pmf_deltatool"
]
=
ac
.
get_deltatool_component
()
COMPONENTS
[
"pmf_unc"
]
=
ac
.
get_uncertainty_component
()
COMPONENTS
[
"pmf_speciesrepartition"
]
=
ac
.
get_specie_repartition_component
()
COMPONENTS
[
"op_beta"
]
=
ac
.
get_op_beta_component
()
COMPONENTS
[
"op_obsvsmodel"
]
=
ac
.
get_op_obs_vs_model_component
()
COMPONENTS
[
"op_contrib"
]
=
ac
.
get_op_contribution_component
()
COMPONENTS
[
"op_contrib_ts"
]
=
ac
.
get_op_contribution_ts_component
()
COMPONENTS
[
"help"
]
=
ac
.
get_about_app_results_component
()
PAGES
=
COMPONENTS
.
keys
()
BUTTONS
=
COMPONENTS
.
keys
()
# do not add species to plot when we already have too many...
tooManyPlot
=
20
...
...
@@ -111,70 +114,44 @@ layout = dbc.Container(
id
=
"items-collapse"
,
navbar
=
True
,
children
=
[
dbc
.
ListGroup
(
id
=
"items-nav"
,
children
=
[
dbc
.
ListGroupItem
(
id
=
"item-rawdata"
,
children
=
[
dbc
.
ListGroup
(
id
=
'item-rawdata-nav'
,
children
=
[
dbc
.
ListGroupItemHeading
(
"Raw data"
),
dbc
.
ListGroupItem
(
'Timeserie'
,
id
=
'item-rawdata-timeserie'
,
action
=
True
,
n_clicks
=
0
),
dbc
.
ListGroupItem
(
'Montlhy'
,
id
=
'item-rawdata-monthly'
,
action
=
True
,
n_clicks
=
0
),
dbc
.
ListGroupItem
(
'Seasonal'
,
id
=
'item-rawdata-seasonal'
,
action
=
True
,
n_clicks
=
0
),
]
)
]
),
dbc
.
ListGroupItem
(
id
=
"item-PMF"
,
children
=
[
dbc
.
ListGroup
(
id
=
'item-PMF-nav'
,
children
=
[
dbc
.
ListGroupItemHeading
(
"PMF factor chemistry"
),
dbc
.
ListGroupItem
(
'Profiles'
,
id
=
'item-pmf-profiles'
,
action
=
True
,
n_clicks
=
0
),
dbc
.
ListGroupItem
(
'DeltaTool'
,
id
=
'item-pmf-deltatool'
,
action
=
True
,
n_clicks
=
0
),
dbc
.
ListGroupItem
(
'Uncertainties'
,
id
=
'item-pmf-uncertainties'
,
action
=
True
,
n_clicks
=
0
),
dbc
.
ListGroupItem
(
'Species repartition'
,
id
=
'item-pmf-speciesrepartition'
,
action
=
True
,
n_clicks
=
0
),
]
)
]
),
dbc
.
ListGroupItem
(
id
=
"item-OP"
,
children
=
[
dbc
.
ListGroup
(
id
=
'item-OP-nav'
,
children
=
[
dbc
.
ListGroupItemHeading
(
"OP model"
),
dbc
.
ListGroupItem
(
'Obs. vs. model'
,
id
=
'item-op-obsvsmodel'
,
action
=
True
,
n_clicks
=
0
),
dbc
.
ListGroupItem
(
'Intrinsic OP'
,
id
=
'item-op-betacoefficient'
,
action
=
True
,
n_clicks
=
0
),
dbc
.
ListGroupItem
(
'OP contribution (all)'
,
id
=
'item-op-contribution'
,
action
=
True
,
n_clicks
=
0
),
dbc
.
ListGroupItem
(
'OP contribution (timeseries)'
,
id
=
'item-op-contribution-ts'
,
action
=
True
,
n_clicks
=
0
),
]
)
]
),
dbc
.
ListGroupItem
(
id
=
"help"
,
children
=
[
dbc
.
ListGroup
(
id
=
"item-help-nav"
,
children
=
[
dbc
.
ListGroupItemHeading
(
"I need help!"
),
dbc
.
ListGroupItem
(
"Don't worry, click here."
,
id
=
"item-help-help"
,
action
=
True
,
n_clicks
=
0
,
active
=
True
)
]
)
]
)
dbc
.
Nav
(
[
dbc
.
ListGroupItemHeading
(
"Raw data"
),
dbc
.
NavLink
(
'Timeserie'
,
href
=
"/results/rd_ts"
,
id
=
'item-rd_ts'
,
n_clicks
=
0
),
dbc
.
NavLink
(
'Montlhy'
,
href
=
"/results/rd_monthly"
,
id
=
'item-rd_monthly'
,
n_clicks
=
0
),
dbc
.
NavLink
(
'Seasonal'
,
href
=
"/results/rd_seasonal"
,
id
=
'item-rd_seasonal'
,
n_clicks
=
0
),
dbc
.
ListGroupItemHeading
(
"PMF factor chemistry"
),
dbc
.
NavLink
(
'Profiles'
,
href
=
'/results/pmf_profiles'
,
id
=
'item-pmf_profiles'
,
n_clicks
=
0
),
dbc
.
NavLink
(
'DeltaTool'
,
href
=
"/results/pmf_deltatool"
,
id
=
'item-pmf_deltatool'
,
n_clicks
=
0
),
dbc
.
NavLink
(
'Uncertainties'
,
href
=
"/results/pmf_unc"
,
id
=
'item-pmf_unc'
,
n_clicks
=
0
),
dbc
.
NavLink
(
'Species repartition'
,
href
=
"/results/pmf_speciesrepartition"
,
id
=
'item-pmf_speciesrepartition'
,
n_clicks
=
0
),
dbc
.
ListGroupItemHeading
(
"OP model"
),
dbc
.
NavLink
(
'Obs. vs. model'
,
href
=
"/results/op_obsvsmodel"
,
id
=
'item-op_obsvsmodel'
,
n_clicks
=
0
),
dbc
.
NavLink
(
'Intrinsic OP'
,
href
=
"/results/op_beta"
,
id
=
'item-op_beta'
,
n_clicks
=
0
),
dbc
.
NavLink
(
'OP contribution (all)'
,
href
=
"/results/op_contrib"
,
id
=
'item-op_contrib'
,
n_clicks
=
0
),
dbc
.
NavLink
(
'OP contribution (timeseries)'
,
href
=
"/results/op_contrib_ts"
,
id
=
'item-op_contrib_ts'
,
n_clicks
=
0
),
dbc
.
ListGroupItemHeading
(
"I need help!"
),
dbc
.
NavLink
(
"Don't worry, click here."
,
href
=
"/results/help"
,
id
=
"item-help"
,
n_clicks
=
0
)
],
),
]
vertical
=
True
,
pills
=
True
)
]
)
]
)
])
],
),
# end fisrt column
# second column
...
...
@@ -191,6 +168,18 @@ layout = dbc.Container(
)
# this callback uses the current pathname to set the active state of the
# corresponding nav link to true, allowing users to tell see page they are on
@
app
.
callback
(
[
Output
(
f
"item-
{
i
}
"
,
"active"
)
for
i
in
PAGES
],
[
Input
(
"master-url"
,
"pathname"
)],
)
def
toggle_active_links
(
pathname
):
if
pathname
==
"/results"
:
# Treat page 1 as the homepage / index
return
[
False
]
*
(
len
(
PAGES
)
-
1
)
+
[
True
]
return
[
pathname
==
f
"/results/
{
i
}
"
for
i
in
PAGES
]
@
app
.
callback
(
Output
(
"items-collapse"
,
"is_open"
),
[
Input
(
"items-toggler"
,
"n_clicks"
)],
...
...
@@ -315,32 +304,9 @@ def update_op_contribution_ts_station_dropdown(value):
Output
(
'source-dropdown'
,
'disabled'
),
Output
(
'specie-dropdown'
,
'disabled'
),
Output
(
'OP-dropdown'
,
'disabled'
),
Output
(
'item-rawdata-timeserie'
,
'active'
),
Output
(
'item-rawdata-monthly'
,
'active'
),
Output
(
'item-rawdata-seasonal'
,
'active'
),
Output
(
'item-pmf-profiles'
,
'active'
),
Output
(
'item-pmf-deltatool'
,
'active'
),
Output
(
'item-pmf-uncertainties'
,
'active'
),
Output
(
'item-pmf-speciesrepartition'
,
'active'
),
Output
(
'item-op-betacoefficient'
,
'active'
),
Output
(
'item-op-obsvsmodel'
,
'active'
),
Output
(
'item-op-contribution'
,
'active'
),
Output
(
'item-op-contribution-ts'
,
'active'
),
Output
(
'item-help-help'
,
'active'
),
],
[
Input
(
'item-rawdata-timeserie'
,
'n_clicks_timestamp'
),
Input
(
'item-rawdata-monthly'
,
'n_clicks_timestamp'
),
Input
(
'item-rawdata-seasonal'
,
'n_clicks_timestamp'
),
Input
(
'item-pmf-profiles'
,
'n_clicks_timestamp'
),
Input
(
'item-pmf-deltatool'
,
'n_clicks_timestamp'
),
Input
(
'item-pmf-uncertainties'
,
'n_clicks_timestamp'
),
Input
(
'item-pmf-speciesrepartition'
,
'n_clicks_timestamp'
),
Input
(
'item-op-betacoefficient'
,
'n_clicks_timestamp'
),
Input
(
'item-op-obsvsmodel'
,
'n_clicks_timestamp'
),
Input
(
'item-op-contribution'
,
'n_clicks_timestamp'
),
Input
(
'item-op-contribution-ts'
,
'n_clicks_timestamp'
),
Input
(
'item-help-help'
,
'n_clicks_timestamp'
),
Input
(
f
"item-
{
i
}
"
,
"n_clicks"
)
for
i
in
PAGES
]
)
def
get_graph_component
(
rd_ts
,
rd_monthly
,
rd_seasonal
,
pmf_profiles
,
...
...
@@ -360,30 +326,16 @@ def get_graph_component(rd_ts, rd_monthly, rd_seasonal, pmf_profiles,
"pmf_profiles"
:
pmf_profiles
,
"pmf_deltatool"
:
pmf_deltatool
,
"pmf_unc"
:
pmf_unc
,
"pmf_s
r
"
:
pmf_sr
,
"pmf_s
peciesrepartition
"
:
pmf_sr
,
"op_beta"
:
op_beta
,
"op_obsvsmodel"
:
op_obsvsmodel
,
"op_contrib"
:
op_contrib
,
"op_contrib_ts"
:
op_contrib_ts
,
"help"
:
help
,
}
active_button
=
{
"rd_ts"
:
False
,
"rd_monthly"
:
False
,
"rd_seasonal"
:
False
,
"pmf_profiles"
:
False
,
"pmf_deltatool"
:
False
,
"pmf_unc"
:
False
,
"pmf_sr"
:
False
,
"op_beta"
:
False
,
"op_obsvsmodel"
:
False
,
"op_contrib"
:
False
,
"op_contrib_ts"
:
False
,
"help"
:
False
,
}
init_val
=
0
clicked
=
"
rd_ts
"
clicked
=
"
help
"
for
nth
,
button
in
enumerate
(
BUTTONS
):
if
new_button_values
[
button
]
is
None
:
continue
...
...
@@ -391,8 +343,7 @@ def get_graph_component(rd_ts, rd_monthly, rd_seasonal, pmf_profiles,
init_val
=
new_button_values
[
button
]
clicked
=
button
active_button
[
clicked
]
=
True
print
(
clicked
)
# ==== Disable drodpown
source_disabled
=
True
specie_disabled
=
True
...
...
@@ -404,37 +355,7 @@ def get_graph_component(rd_ts, rd_monthly, rd_seasonal, pmf_profiles,
if
clicked
in
[
'rd_ts'
,
'rd_monthly'
,
'rd_seasonal'
,
'op_beta'
,
'op_obsvsmodel'
,
'op_contrib'
,
'op_contrib_ts'
]:
OP_disabled
=
False
# ==== Set active button
rd_ts_a
=
rd_monthly_a
=
rd_seasonal_a
=
pmf_profiles_a
=
pmf_deltatool_a
=
pmf_unc_a
=
pmf_sr_a
=
op_beta_a
=
op_obsvsmodel_a
=
op_contrib_a
=
op_contrib_ts_a
=
help_a
=
False
if
clicked
==
"rd_ts"
:
rd_ts_a
=
True
elif
clicked
==
"rd_monthly"
:
rd_monthly_a
=
True
elif
clicked
==
"rd_seasonal"
:
rd_seasonal_a
=
True
elif
clicked
==
"pmf_profiles"
:
pmf_profiles_a
=
True
elif
clicked
==
"pmf_deltatool"
:
pmf_deltatool_a
=
True
elif
clicked
==
"pmf_unc"
:
pmf_unc_a
=
True
elif
clicked
==
"pmf_sr"
:
pmf_sr_a
=
True
elif
clicked
==
"op_beta"
:
op_beta_a
=
True
elif
clicked
==
"op_obsvsmodel"
:
op_obsvsmodel_a
=
True
elif
clicked
==
"op_contrib"
:
op_contrib_a
=
True
elif
clicked
==
"op_contrib_ts"
:
op_contrib_ts_a
=
True
elif
clicked
==
"help"
:
help_a
=
True
return
(
COMPONENTS
[
clicked
],
source_disabled
,
specie_disabled
,
OP_disabled
,
rd_ts_a
,
rd_monthly_a
,
rd_seasonal_a
,
pmf_profiles_a
,
pmf_deltatool_a
,
pmf_unc_a
,
pmf_sr_a
,
op_beta_a
,
op_obsvsmodel_a
,
op_contrib_a
,
op_contrib_ts_a
,
help_a
)
return
(
COMPONENTS
[
clicked
],
source_disabled
,
specie_disabled
,
OP_disabled
)
@
app
.
callback
(
Output
(
'op-contribution-ts-station-dropdown'
,
'style'
),
[
...
...
index.py
View file @
58792d77
import
re
import
dash_core_components
as
dcc
import
dash_html_components
as
html
import
dash_bootstrap_components
as
dbc
from
dash.dependencies
import
Input
,
Output
,
State
from
dash.exceptions
import
PreventUpdate
from
app_main
import
app
from
apps
import
app_contact
,
app_results
,
app_deconvolOP
,
app_estimateOP
...
...
@@ -78,6 +80,9 @@ app.title = "OP apportionment"
def
display_page
(
pathname
):
# return app_single.layout
print
(
pathname
)
if
re
.
search
(
"/.*\/.+"
,
pathname
):
raise
PreventUpdate
()
if
pathname
is
None
or
pathname
==
'/'
:
return
app_deconvolOP
.
layout
elif
pathname
[:
len
(
'/results'
)]
==
'/results'
:
...
...
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