Skip to content

Commit 2f41f7e

Browse files
authored
Merge pull request #22 from cognizant-ai-labs/bigdemo
Giant redo of layout for bigger demos
2 parents ec88a0b + b700900 commit 2f41f7e

21 files changed

+919
-961
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,8 @@ __pycache__
66
temp/
77
.vscode
88
results/
9+
animations/
10+
11+
input_specs.jsonl
912

1013
!app/results

Dockerfile

+1-4
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ RUN pip install --no-cache-dir --upgrade pip && \
2020
COPY . .
2121

2222
# Download En-ROADS SDK and extract it
23-
ENV ENROADS_URL=$ENROADS_URL
24-
ENV ENROADS_ID=$ENROADS_ID
25-
ENV ENROADS_PASSWORD=$ENROADS_PASSWORD
26-
RUN python -m enroadspy.download_sdk
23+
RUN python -m enroadspy.load_sdk
2724

2825
# Expose Flask (Dash) port
2926
EXPOSE 4057

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ Immediate action is required to combat climate change. The technology behind [Co
77
En-ROADS is a climate change simulator developed by [Climate Interactive](https://www.climateinteractive.org/). We have created a wrapper around the SDK to make it simple to use in a Python application which can be found in `enroadspy`. See `enroads_runner.py` for the main class that runs the SDK. The SDK is not included in this repository and access to it is very limited. If you would like to run this code, please contact Project Resilience at [daniel.young2@cognizant.com](mailto:daniel.young2@cognizant.com).
88

99
### Installation
10-
This project was created with Python 3.10.14. Run `pip install -r requirements.txt` to install the required packages. Then run `python -m enroadspy.download_sdk` to download the SDK. In order to download the SDK environment variables must be set.
10+
This project was created with Python 3.10.14. Run `pip install -r requirements.txt` to install the required packages.
11+
12+
The En-ROADS SDK must be loaded for this project to run. This can be done with `python -m enroadspy.load_sdk`, after the proper permissions are granted and environment variables are set.
1113

1214
## Evolution
1315

app/app.py

+25-12
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
from dash import html
66
import dash_bootstrap_components as dbc
77

8-
from app.components.intro import IntroComponent
98
from app.components.context import ContextComponent
109
from app.components.filter import FilterComponent
10+
from app.components.header.header import HeaderComponent
1111
from app.components.outcome import OutcomeComponent
1212
from app.components.link import LinkComponent
13-
from app.components.references import ReferencesComponent
13+
1414
from app.utils import EvolutionHandler
1515

1616
evolution_handler = EvolutionHandler()
@@ -19,12 +19,11 @@
1919
# The candidates are sorted by rank then distance so the 'best' ones are the first 10
2020
sample_idxs = list(range(10))
2121

22-
intro_component = IntroComponent()
2322
context_component = ContextComponent()
2423
filter_component = FilterComponent(metrics)
24+
header_component = HeaderComponent()
2525
outcome_component = OutcomeComponent(evolution_handler)
26-
link_component = LinkComponent(sample_idxs, actions)
27-
references_component = ReferencesComponent()
26+
link_component = LinkComponent(actions)
2827

2928
# Initialize the Dash app
3029
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP, dbc.icons.BOOTSTRAP, "assets/styles.css"])
@@ -33,18 +32,32 @@
3332

3433
context_component.register_callbacks(app)
3534
filter_component.register_callbacks(app)
35+
header_component.register_callbacks(app)
3636
outcome_component.register_callbacks(app)
3737
link_component.register_callbacks(app)
3838

39-
# Layout of the app
4039
app.layout = html.Div(
4140
children=[
42-
intro_component.create_intro_div(),
43-
context_component.create_context_div(),
44-
filter_component.create_filter_div(),
45-
outcome_component.create_outcomes_div(),
46-
link_component.create_link_div(),
47-
references_component.create_references_div()
41+
dbc.Container(
42+
id="main-page",
43+
fluid=True,
44+
children=[
45+
header_component.create_div(),
46+
dbc.Row(outcome_component.create_div()),
47+
dbc.Row(
48+
className="mb-5",
49+
children=[
50+
dbc.Col(
51+
context_component.create_div()
52+
),
53+
dbc.Col(
54+
filter_component.create_div()
55+
)
56+
]
57+
),
58+
dbc.Row(link_component.create_div())
59+
]
60+
)
4861
]
4962
)
5063

app/assets/custom.css

+12-19
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
1-
body {
2-
background-image: url("https://upload.wikimedia.org/wikipedia/commons/5/54/Power_County_Wind_Farm_002.jpg");
3-
background-size: cover;
4-
background-position: center;
5-
background-attachment: fixed;
6-
}
7-
81
/* restyle radio items */
92
.radio-group .form-check {
10-
padding-left: 0;
11-
}
12-
13-
.radio-group .btn-group > .form-check:not(:last-child) > .btn {
14-
border-top-right-radius: 0;
15-
border-bottom-right-radius: 0;
16-
}
3+
padding-left: 0;
4+
}
175

18-
.radio-group .btn-group > .form-check:not(:first-child) > .btn {
19-
border-top-left-radius: 0;
20-
border-bottom-left-radius: 0;
21-
margin-left: -1px;
22-
}
6+
.radio-group .btn-group > .form-check:not(:last-child) > .btn {
7+
border-top-right-radius: 0;
8+
border-bottom-right-radius: 0;
9+
}
10+
11+
.radio-group .btn-group > .form-check:not(:first-child) > .btn {
12+
border-top-left-radius: 0;
13+
border-bottom-left-radius: 0;
14+
margin-left: -1px;
15+
}

app/classes.py

-10
This file was deleted.

app/components/component.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""
2+
Interface defining what a component should look like. This lets us easily and dynamically call all their callbacks
3+
and then add them to the main app layout. Single components should register all their callbacks at once and only
4+
have a single div that they render.
5+
"""
6+
from abc import ABC, abstractmethod
7+
8+
from dash import Dash, html
9+
10+
11+
class Component(ABC):
12+
"""
13+
Interface for components. They must register their callbacks and create their div.
14+
"""
15+
@abstractmethod
16+
def create_div(self) -> html.Div:
17+
"""
18+
Creates the div housing the component. This gets called by the main layout.
19+
"""
20+
21+
@abstractmethod
22+
def register_callbacks(self, app: Dash):
23+
"""
24+
Registers the callbacks for the component. This gets called by the main app.
25+
"""

0 commit comments

Comments
 (0)