-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
123 lines (105 loc) · 3.51 KB
/
app.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
from dash import Dash, dcc, html, Input, Output, callback, ctx
import sys
import dash_bootstrap_components as dbc
import json
sys.path.append("./")
import config
from layout import sidebar, content
import map_utils
app = Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
server = app.server
# Set defaults
org_level = "NHS England (Region)"
dimension = "AgeAtBookingMotherGroup"
year = "2022-23"
chart_type = "Bar Chart"
app.layout = html.Div(
[
dcc.Location(id="url"),
dbc.Row(
[
dbc.Col(sidebar, width=1),
dbc.Col(content, width=11, style={"padding": "0"}),
]
),
]
)
@callback(
Output("bar-chart", "figure"),
Output("chart_title", "children"),
Output("chart_description", "children"),
Input("dimension-dropdown", "value"),
Input("map", "selectedData"),
Input("org_level_button", "value"),
Input("year_button", "value"),
Input("chart_button", "value"),
)
def display_chart(dimension, selectedData, org_level, year, chart_type):
location = "All Submitters"
if selectedData is None and not (
org_level == "Provider"
and dimension in config.special_dimensions
and chart_type == "Time Series"
):
org_level = "National"
else:
if org_level == "NHS England (Region)":
if "location" in selectedData["points"][0]:
location = selectedData["points"][0]["location"]
else:
org_level = "National"
elif org_level == "Provider" and not (selectedData == None):
if "customdata" in selectedData["points"][0]:
location = selectedData["points"][0]["customdata"][0]
else:
org_level = "National"
if (
selectedData is None
and org_level == "Provider"
and dimension in config.special_dimensions
and chart_type == "Time Series"
):
org_level = "Provider"
elif (
selectedData is not None
and org_level == "Provider"
and dimension in config.special_dimensions
and chart_type == "Time Series"
):
org_level = "Provider"
location = selectedData["points"][0]["customdata"][0]
if ctx.triggered_id == "org_level_button":
location = "All Submitters"
org_level = "National"
fig = map_utils.get_chart(org_level, dimension, year, chart_type, location)
title, description = map_utils.get_chart_title(
dimension, year, location, chart_type
)
return fig, title, description
@callback(
Output("map", "figure"),
Output("map_title", "children"),
Output("map_description", "children"),
Output("selectedDataDisplay", "children"),
Output("selectedpointsdisplay", "children"),
Input("dimension-dropdown", "value"),
Input("map", "selectedData"),
Input("org_level_button", "value"),
Input("year_button", "value"),
)
def display_map(dimension, selectedData, org_level, year):
if selectedData is None or ctx.triggered_id == "org_level_button":
selectedpoints = None
else:
selectedpoints = [point["pointIndex"] for point in selectedData["points"]]
fig = map_utils.get_map(org_level, dimension, year, selectedpoints=selectedpoints)
map_title, map_description = map_utils.get_map_title(dimension, year, org_level)
return (
fig,
map_title,
map_description,
json.dumps(selectedData),
json.dumps(selectedpoints),
)
if __name__ == "__main__":
app.run(debug=True)