Skip to content

Commit 4c4bea0

Browse files
Deployment 32. Passing the app.
1 parent c1da584 commit 4c4bea0

File tree

5 files changed

+46
-33
lines changed

5 files changed

+46
-33
lines changed

dash_app/app.py

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,15 @@
2424
from dash.exceptions import PreventUpdate
2525
from dash import dcc
2626

27-
print("before sourced scripts")
2827
# SOURCED SCRIPTS
2928
from definitions import CONNECT_TO_LAMBDA, PORT, ZARRPATH, s3
3029
if CONNECT_TO_LAMBDA:
3130
from msdlive_utils import get_bytes
3231
from io import BytesIO
3332

34-
print("before more sourced scripts")
3533
from src.reader import open_as_raster
3634
from src.deckgl2 import plot_map
37-
from layout import create_app, tech_pathways_df, src_meta, all_options
35+
from layout import app, tech_pathways_df, src_meta, all_options
3836
from layout import intro_text, section_headers, title_text, description_text, funding_text, data_text
3937

4038
# -------------------------------
@@ -62,21 +60,21 @@
6260
# Right-hand panel.
6361
# -------------------------------------------
6462

65-
@callback(
63+
@app.callback(
6664
Output('subtech-select', 'options'),
6765
Input('tech-select', 'value'))
6866
def set_level2_options(tech):
6967
logger.info(f"Tech clicked. Input value: {tech}")
7068
return [{'label': i, 'value': i} for i in all_options[tech]]
7169

72-
@callback(
70+
@app.callback(
7371
Output('subtech-select', 'value'),
7472
Input('subtech-select', 'options'))
7573
def set_level2_value(available_options):
7674
return available_options[0]['value']
7775

7876

79-
@callback(
77+
@app.callback(
8078
Output('feature-select', 'options'),
8179
Input('tech-select', 'value'),
8280
Input('subtech-select', 'value'))
@@ -85,14 +83,14 @@ def set_level2_options(tech, subtech):
8583
return [{'label': i, 'value': i} for i in all_options[tech][subtech]]
8684

8785

88-
@callback(
86+
@app.callback(
8987
Output('feature-select', 'value'),
9088
Input('feature-select', 'options'))
9189
def set_level2_value(available_options):
9290
return available_options[0]['value']
9391

9492

95-
@callback(
93+
@app.callback(
9694
Output('carbon-capture-select', 'options'),
9795
Input('tech-select', 'value'),
9896
Input('subtech-select', 'value'),
@@ -101,14 +99,14 @@ def set_level2_options(tech, subtech, feature):
10199
logger.info(f"Feature clicked. Input value: {feature}")
102100
return [{'label': i, 'value': i} for i in all_options[tech][subtech][feature]]
103101

104-
@callback(
102+
@app.callback(
105103
Output('carbon-capture-select', 'value'),
106104
Input('carbon-capture-select', 'options'))
107105
def set_level2_value(available_options):
108106
return available_options[0]['value']
109107

110108

111-
@callback(
109+
@app.callback(
112110
Output('cooling-type-select', 'options'),
113111
Input('tech-select', 'value'),
114112
Input('subtech-select', 'value'),
@@ -119,14 +117,14 @@ def set_level2_options(tech, subtech, feature, is_ccs):
119117
logger.info(f"CCS clicked. Input value: {is_ccs}")
120118
return [{'label': i, 'value': i} for i in all_options[tech][subtech][feature][is_ccs]]
121119

122-
@callback(
120+
@app.callback(
123121
Output('cooling-type-select', 'value'),
124122
Input('cooling-type-select', 'options'))
125123
def set_level2_value(available_options):
126124
return available_options[0]['value']
127125

128126

129-
@callback(
127+
@app.callback(
130128
Output('capacity-factor-select', 'options'),
131129
Input('tech-select', 'value'),
132130
Input('subtech-select', 'value'),
@@ -141,14 +139,14 @@ def set_level2_options(tech, subtech, feature, is_ccs, cooling_type):
141139
options = [options]
142140
return [{'label': i, 'value': i} for i in options]
143141

144-
@callback(
142+
@app.callback(
145143
Output('capacity-factor-select', 'value'),
146144
Input('capacity-factor-select', 'options'))
147145
def set_level2_value(available_options):
148146
return available_options[0]['value']
149147

150148

151-
@callback(
149+
@app.callback(
152150
[
153151
Output(component_id='feature-select-container', component_property='style'),
154152
Output(component_id='carbon-capture-select-container', component_property='style'),
@@ -191,7 +189,7 @@ def show_hide_element(feature, is_ccs, cooling, capacity_factor):
191189
# DeckGL Mapping.
192190
# -------------------------------------------
193191

194-
@callback(
192+
@app.callback(
195193
# [,
196194
# # Output('last-btn-pressed', 'children')
197195
# ],
@@ -280,7 +278,7 @@ def map(year, ssp, tech, subtech, feature, is_ccs, coolingtype, capacity_factor,
280278
# Map settings and tools.
281279
# -------------------------------------------
282280

283-
@callback(
281+
@app.callback(
284282
Output('banner', 'style'),
285283
Output('page-body', 'style'),
286284
Input('btn-text', 'children')
@@ -330,7 +328,7 @@ def update_mode(value):
330328
return header_banner, page_body
331329

332330

333-
@callback(
331+
@app.callback(
334332
[
335333
Output('button1', 'className'),
336334
Output('button2', 'className'),
@@ -354,7 +352,7 @@ def update_output(n_clicks1, n_clicks2):
354352
else:
355353
return "button-selected", "button", "button1" # initialize on the sun (check if only falls into here for this case, b/c otherwise could be this 'button', 'button-selected' )
356354

357-
@callback(
355+
@app.callback(
358356
[Output(component_id="expandable-box", component_property="style"),
359357
Output(component_id="expandable-box", component_property="children"),
360358
],
@@ -420,7 +418,7 @@ def expand_box(expand_clicks, close_clicks):
420418
# Older callbacks.
421419
# -----------------------------------------------------------------------------
422420

423-
# @callback(
421+
# @app.callback(
424422
# Output('adjust-mode', 'color'),
425423
# # Output('output', 'children'),
426424
# Input('adjust-mode', 'value')
@@ -432,7 +430,7 @@ def expand_box(expand_clicks, close_clicks):
432430
# return 'blue'
433431

434432

435-
# @callback(
433+
# @app.callback(
436434
# Output("visibility", "src"),
437435
# Input("visibility-btn", "n_clicks"),
438436
# )
@@ -451,8 +449,8 @@ def expand_box(expand_clicks, close_clicks):
451449
print("Sending app to the get_wsgi_handler ... ")
452450
else:
453451
if __name__ == "__main__":
454-
create_app().run(debug=False)
455-
# app.run_server(port=PORT, debug=False#, use_reloader=True, dev_tools_ui=True,
456-
# # dev_tools_props_check=True,
457-
# # dev_tools_hot_reload=False,
458-
# ) # disabling hot reloading
452+
# create_app().run(debug=False)
453+
app.run(port=PORT, debug=False#, use_reloader=True, dev_tools_ui=True,
454+
# dev_tools_props_check=True,
455+
# dev_tools_hot_reload=False,
456+
) # disabling hot reloading

dash_app/definitions.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
# CONNECT TO PATHS IN REPO
1717
METADATA_DIR = "./metadata" # in the repo
18+
MAP_DIR = "data"
1819

1920
# CONNECT TO AWS S3
2021
script_dir = os.path.abspath("../../../")
@@ -36,12 +37,13 @@
3637

3738
if CONNECT_TO_LAMBDA:
3839

39-
print("DEPLOYMENT 31")
40+
print("DEPLOYMENT 32")
4041

4142
SERVE_LOCALLY = False
4243

4344
# AWS lambda
4445
METADATA_DIR = "./dash_app/metadata" # in the repo
46+
MAP_DIR = "dash_app/data"
4547
LAMBDA_TASK_ROOT = os.getenv('LAMBDA_TASK_ROOT', "")
4648
DIR = os.path.join(LAMBDA_TASK_ROOT, "dash_app")
4749
DATASET_ID = "w85m1-f5148" # prod # 1ffea-emt93: MSD-LIVE added dataset id that goes to DEV

dash_app/layout.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,4 +695,9 @@ def page_card():
695695
],
696696
)
697697

698+
699+
logger.info("Completed the layout.")
700+
698701
return app
702+
703+
app = create_app()

dash_app/src/deckgl2.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
33

4+
import os
45
import time
56
import json
67
import dash_deck
@@ -10,6 +11,7 @@
1011
import numpy as np
1112
from dash import html
1213
from src.deck_utilities import *
14+
from definitions import MAP_DIR
1315

1416
try:
1517
from pydeck.core.constants import COORDINATE_SYSTEM
@@ -31,10 +33,11 @@ class COORDINATE_SYSTEM:
3133
}
3234

3335
# no dash_app locally
34-
LAND_NORTHAMERICA = gpd.read_file("dash_app/data/static_layer_data/land.geojson")
36+
37+
LAND_NORTHAMERICA = gpd.read_file(os.path.join(MAP_DIR, "static_layer_data/land.geojson"))
3538
# OCEANS = gpd.read_file("data/static_layer_data/oceans.geojson")
36-
STATES = gpd.read_file("dash_app/data/static_layer_data/states.geojson")
37-
TRANSMISSION_LINES = gpd.read_file("dash_app/data/static_layer_data/transmission_lines.geojson")
39+
STATES = gpd.read_file(os.path.join(MAP_DIR, "static_layer_data/states.geojson")) # "dash_app/data/static_layer_data/states.geojson")
40+
TRANSMISSION_LINES = gpd.read_file(os.path.join(MAP_DIR, "static_layer_data/transmission_lines.geojson")) # ("dash_app/data/static_layer_data/transmission_lines.geojson")
3841

3942
def plot_static_layers(styling_dict):
4043

lambda_function.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,25 @@
88

99
# SOURCED SCRIPT
1010
# from dash_app.test_app import create_app
11-
# from dash_app.app import app
12-
from dash_app.layout import create_app
11+
from dash_app.app import app
12+
# from dash_app.layout import create_app
1313

1414
@lru_cache(maxsize=5)
1515
def build_handler(url_prefix: str) -> "Dash":
1616

1717
# If there's no prefix, it's a custom domain
1818
if url_prefix is None or url_prefix == "":
19-
return make_lambda_handler(wsgi_app=create_app().server, binary_support=True)
19+
# return make_lambda_handler(wsgi_app=create_app().server, binary_support=True)
20+
return make_lambda_handler(wsgi_app=app.server, binary_support=True)
2021

2122
# If there's a prefix we're dealing with an API gateway stage
2223
# and need to return the appropriate urls.
24+
# return make_lambda_handler(
25+
# wsgi_app=create_app({"url_base_pathname": url_prefix}).server,
26+
# binary_support=True,
27+
# )
2328
return make_lambda_handler(
24-
wsgi_app=create_app({"url_base_pathname": url_prefix}).server,
29+
wsgi_app=app.server,
2530
binary_support=True,
2631
)
2732

0 commit comments

Comments
 (0)