3
3
4
4
#! _INPUTS should be considered for moving else where
5
5
"""
6
- import dash_html_components as dhc
7
-
8
6
from typing import List , Dict , Any , Tuple
9
7
from collections import OrderedDict
10
8
11
9
from dash .dependencies import Input as CallbackInput , Output
12
10
from dash .development .base_component import ComponentMeta
13
- from dash_html_components import Br
11
+ from dash_html_components import Br , Div , Nav
14
12
15
13
from penn_chime .defaults import RateLos
16
14
from penn_chime .parameters import Parameters
17
15
18
16
from chime_dash .app .components .base import Component
19
- from chime_dash .app .utils .templates import create_switch_input , create_number_input , create_header , create_button , \
20
- create_link
17
+ from chime_dash .app .utils .templates import (
18
+ create_switch_input ,
19
+ create_number_input ,
20
+ create_header ,
21
+ create_button ,
22
+ create_link ,
23
+ )
21
24
22
25
FLOAT_INPUT_MIN = 0.001
23
26
FLOAT_INPUT_STEP = "any"
24
27
25
28
_INPUTS = OrderedDict (
26
29
regional_parameters = {"type" : "header" , "size" : "h3" },
27
- market_share = {"type" : "number" , "min" : FLOAT_INPUT_MIN , "step" : FLOAT_INPUT_STEP , "max" : 100.0 , "percent" : True },
30
+ market_share = {
31
+ "type" : "number" ,
32
+ "min" : FLOAT_INPUT_MIN ,
33
+ "step" : FLOAT_INPUT_STEP ,
34
+ "max" : 100.0 ,
35
+ "percent" : True ,
36
+ },
28
37
susceptible = {"type" : "number" , "min" : 1 , "step" : 1 },
29
38
known_infected = {"type" : "number" , "min" : 0 , "step" : 1 },
30
39
current_hospitalized = {"type" : "number" , "min" : 0 , "step" : 1 },
50
59
"min" : 0.0 ,
51
60
"step" : FLOAT_INPUT_STEP ,
52
61
"max" : 100.0 ,
53
- "percent" : True
62
+ "percent" : True ,
54
63
},
55
64
ventilated_rate = {
56
65
"type" : "number" ,
69
78
show_tables = {"type" : "switch" , "value" : False },
70
79
show_tool_details = {"type" : "switch" , "value" : False },
71
80
show_additional_projections = {"type" : "switch" , "value" : False },
72
- save_as_pdf = {"type" : "button" , "property" : "n_clicks" },
73
- pdf_file_link = {"type" : "link" , "property" : "href" }
81
+ download_as_pdf_link = {"type" : "link" },
74
82
)
75
83
76
84
@@ -79,20 +87,27 @@ class Sidebar(Component):
79
87
contains the various inputs used to interact
80
88
with the model.
81
89
"""
90
+
82
91
# localization temp. for widget descriptions
83
92
localization_file = "sidebar.yml"
84
93
85
94
callback_inputs = OrderedDict (
86
- (key , CallbackInput (component_id = key , component_property = _INPUTS [key ].get ("property" , "value" )))
87
- for key in _INPUTS if _INPUTS [key ]["type" ] not in ("header" , "link" )
95
+ (
96
+ key ,
97
+ CallbackInput (
98
+ component_id = key ,
99
+ component_property = _INPUTS [key ].get ("property" , "value" ),
100
+ ),
101
+ )
102
+ for key in _INPUTS
103
+ if _INPUTS [key ]["type" ] not in ("header" , "link" )
88
104
)
89
105
90
- callback_outputs = [Output (component_id = 'pdf_file_link' , component_property = 'href' ),
91
- Output (component_id = 'pdf_file_link' , component_property = 'children' )]
106
+ callback_outputs = [
107
+ Output (component_id = "download_as_pdf_link" , component_property = "href" )
108
+ ]
92
109
93
110
def __init__ (self , * args , ** kwargs ):
94
- self ._save_to_pdf = False
95
- self .pdf_button_clicks = 0
96
111
super ().__init__ (* args , ** kwargs )
97
112
98
113
@staticmethod
@@ -135,7 +150,7 @@ def get_html(self) -> List[ComponentMeta]:
135
150
element = create_button (idx , self .content )
136
151
elif data ["type" ] == "link" :
137
152
elements .append (Br ())
138
- element = create_link (idx )
153
+ element = create_link (idx , self . content )
139
154
else :
140
155
raise ValueError (
141
156
"Failed to parse input '{idx}' with data '{data}'" .format (
@@ -144,14 +159,11 @@ def get_html(self) -> List[ComponentMeta]:
144
159
)
145
160
elements .append (element )
146
161
147
- sidebar = dhc . Nav (
148
- children = dhc . Div (
162
+ sidebar = Nav (
163
+ children = Div (
149
164
children = elements ,
150
165
className = "p-4" ,
151
- style = {
152
- "height" : "calc(100vh - 48px)" ,
153
- "overflowY" : "auto" ,
154
- },
166
+ style = {"height" : "calc(100vh - 48px)" , "overflowY" : "auto" ,},
155
167
),
156
168
className = "col-md-3" ,
157
169
style = {
@@ -160,23 +172,22 @@ def get_html(self) -> List[ComponentMeta]:
160
172
"bottom" : 0 ,
161
173
"left" : 0 ,
162
174
"zIndex" : 100 ,
163
- "boxShadow" : "inset -1px 0 0 rgba(0, 0, 0, .1)"
164
- }
175
+ "boxShadow" : "inset -1px 0 0 rgba(0, 0, 0, .1)" ,
176
+ },
165
177
)
166
178
167
179
return [sidebar ]
168
180
169
- def save_to_pdf (self , kwargs ):
170
- """
171
- Return status of save to pdf flag and set it off.
172
- """
173
- if kwargs .get ('save_as_pdf' , 0 ) and kwargs .get ('save_as_pdf' , 0 ) > self .pdf_button_clicks :
174
- self .pdf_button_clicks = kwargs .get ('save_as_pdf' , '0' )
175
- return True
176
- return False
177
-
178
181
def callback ( # pylint: disable=W0613, R0201
179
182
self , * args , ** kwargs
180
183
) -> List [Dict [str , Any ]]:
181
- return [kwargs .get ('pdf_url' , '' ),
182
- self .content ['download_report' ] if kwargs .get ('pdf_url' , None ) else None ]
184
+
185
+ url = "/download-as-pdf?" + "&" .join (
186
+ [
187
+ "{key}={val}" .format (key = key , val = val )
188
+ for key , val in kwargs .items ()
189
+ if not key in ["model" , "pars" ] and val is not None
190
+ ]
191
+ )
192
+
193
+ return [url ]
0 commit comments