Skip to content

Commit 2e90551

Browse files
committed
Formatting.
1 parent 409caf4 commit 2e90551

File tree

14 files changed

+368
-657
lines changed

14 files changed

+368
-657
lines changed

Makefile

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ make clean - Remove cached files and lock files.
1212
endef
1313
export HELP
1414

15-
.PHONY: run restart deploy update clean help
15+
.PHONY: run deploy update format clean help
1616

1717

1818
requirements: .requirements.txt
19+
env: .venv/bin/activate
1920

2021

2122
.requirements.txt: requirements.txt
@@ -27,8 +28,8 @@ all help:
2728

2829

2930
.PHONY: run
30-
run:
31-
$(shell . .venv/bin/activate && python3 wsgi.py)
31+
run: env
32+
$(shell . .venv/bin/activate && flask run)
3233

3334

3435
.PHONY: deploy
@@ -37,17 +38,16 @@ deploy:
3738

3839

3940
.PHONY: update
40-
update:
41-
poetry shell && poetry update
42-
pip freeze > requirements.txt
43-
exit
41+
update: env
42+
.venv/bin/python3 -m pip install -U pip
43+
poetry update
44+
poetry export -f requirements.txt --output requirements.txt --without-hashes
4445

4546

4647
.PHONY: format
47-
format: requirements
48-
$(shell . .venv/bin/activate)
49-
$(shell isort -rc ./)
50-
$(shell black ./)
48+
format: env
49+
$(shell . .venv/bin/activate && isort -rc ./)
50+
$(shell . .venv/bin/activate && black ./)
5151

5252

5353
.PHONY: clean

Pipfile

Lines changed: 0 additions & 22 deletions
This file was deleted.

Pipfile.lock

Lines changed: 0 additions & 320 deletions
This file was deleted.

config.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
"""Flask config."""
22
from os import environ, path
3+
34
from dotenv import load_dotenv
45

56
BASE_DIR = path.abspath(path.dirname(__file__))
6-
load_dotenv(path.join(BASE_DIR, '.env'))
7+
load_dotenv(path.join(BASE_DIR, ".env"))
78

89

910
class Config:
1011
"""Flask configuration variables."""
1112

1213
# General Config
13-
FLASK_APP = environ.get('FLASK_APP')
14-
FLASK_ENV = environ.get('FLASK_ENV')
15-
SECRET_KEY = environ.get('SECRET_KEY')
14+
FLASK_APP = environ.get("FLASK_APP")
15+
FLASK_ENV = environ.get("FLASK_ENV")
16+
SECRET_KEY = environ.get("SECRET_KEY")
1617

1718
# Assets
18-
LESS_BIN = environ.get('LESS_BIN')
19-
ASSETS_DEBUG = environ.get('ASSETS_DEBUG')
20-
LESS_RUN_IN_DEBUG = environ.get('LESS_RUN_IN_DEBUG')
19+
LESS_BIN = environ.get("LESS_BIN")
20+
ASSETS_DEBUG = environ.get("ASSETS_DEBUG")
21+
LESS_RUN_IN_DEBUG = environ.get("LESS_RUN_IN_DEBUG")
2122

2223
# Static Assets
23-
STATIC_FOLDER = 'static'
24-
TEMPLATES_FOLDER = 'templates'
25-
COMPRESSOR_DEBUG = environ.get('COMPRESSOR_DEBUG')
24+
STATIC_FOLDER = "static"
25+
TEMPLATES_FOLDER = "templates"
26+
COMPRESSOR_DEBUG = environ.get("COMPRESSOR_DEBUG")

deploy.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
if [ -d ".venv" ]
44
then
5-
source .venv/bin/activate
5+
. .venv/bin/activate
66
pip install -r requirements.txt
77
python3 wsgi.py
88
else
99
python3 -m venv .venv
10-
source .venv/bin/activate
10+
. .venv/bin/activate
1111
python3 -m pip install --upgrade pip
1212
pip install -r requirements.txt
1313
python3 wsgi.py

plotlyflask_tutorial/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
def init_app():
77
"""Construct core Flask application with embedded Dash app."""
88
app = Flask(__name__, instance_relative_config=False)
9-
app.config.from_object('config.Config')
9+
app.config.from_object("config.Config")
1010
assets = Environment()
1111
assets.init_app(app)
1212

@@ -17,6 +17,7 @@ def init_app():
1717

1818
# Import Dash application
1919
from .plotlydash.dashboard import init_dashboard
20+
2021
app = init_dashboard(app)
2122

2223
# Compile static assets

plotlyflask_tutorial/assets.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ def compile_static_assets(assets):
1313
assets.auto_build = True
1414
assets.debug = False
1515
less_bundle = Bundle(
16-
'less/*.less',
17-
filters='less,cssmin',
18-
output='dist/css/styles.css',
19-
extra={'rel': 'stylesheet/less'}
16+
"less/*.less",
17+
filters="less,cssmin",
18+
output="dist/css/styles.css",
19+
extra={"rel": "stylesheet/less"},
2020
)
21-
assets.register('less_all', less_bundle)
22-
if app.config['FLASK_ENV'] == 'development':
21+
assets.register("less_all", less_bundle)
22+
if app.config["FLASK_ENV"] == "development":
2323
less_bundle.build()
2424
return assets

plotlyflask_tutorial/plotlydash/dashboard.py

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
"""Instantiate a Dash app."""
2-
import numpy as np
3-
import pandas as pd
42
import dash
5-
import dash_table
6-
import dash_html_components as html
73
import dash_core_components as dcc
4+
import dash_html_components as html
5+
import dash_table
6+
import numpy as np
7+
import pandas as pd
8+
89
from .data import create_dataframe
910
from .layout import html_layout
1011

@@ -13,11 +14,11 @@ def init_dashboard(server):
1314
"""Create a Plotly Dash dashboard."""
1415
dash_app = dash.Dash(
1516
server=server,
16-
routes_pathname_prefix='/dashapp/',
17+
routes_pathname_prefix="/dashapp/",
1718
external_stylesheets=[
18-
'/static/dist/css/styles.css',
19-
'https://fonts.googleapis.com/css?family=Lato'
20-
]
19+
"/static/dist/css/styles.css",
20+
"https://fonts.googleapis.com/css?family=Lato",
21+
],
2122
)
2223

2324
# Load DataFrame
@@ -28,38 +29,41 @@ def init_dashboard(server):
2829

2930
# Create Layout
3031
dash_app.layout = html.Div(
31-
children=[dcc.Graph(
32-
id='histogram-graph',
33-
figure={
34-
'data': [{
35-
'x': df['complaint_type'],
36-
'text': df['complaint_type'],
37-
'customdata': df['key'],
38-
'name': '311 Calls by region.',
39-
'type': 'histogram'
40-
}],
41-
'layout': {
42-
'title': 'NYC 311 Calls category.',
43-
'height': 500,
44-
'padding': 150
45-
}
46-
}),
47-
create_data_table(df)
32+
children=[
33+
dcc.Graph(
34+
id="histogram-graph",
35+
figure={
36+
"data": [
37+
{
38+
"x": df["complaint_type"],
39+
"text": df["complaint_type"],
40+
"customdata": df["key"],
41+
"name": "311 Calls by region.",
42+
"type": "histogram",
43+
}
44+
],
45+
"layout": {
46+
"title": "NYC 311 Calls category.",
47+
"height": 500,
48+
"padding": 150,
49+
},
50+
},
51+
),
52+
create_data_table(df),
4853
],
49-
id='dash-container'
54+
id="dash-container",
5055
)
5156
return dash_app.server
5257

5358

5459
def create_data_table(df):
5560
"""Create Dash datatable from Pandas DataFrame."""
5661
table = dash_table.DataTable(
57-
id='database-table',
62+
id="database-table",
5863
columns=[{"name": i, "id": i} for i in df.columns],
59-
data=df.to_dict('records'),
64+
data=df.to_dict("records"),
6065
sort_action="native",
61-
sort_mode='native',
62-
page_size=300
66+
sort_mode="native",
67+
page_size=300,
6368
)
6469
return table
65-
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
"""Prepare data for Plotly Dash."""
2-
import pandas as pd
32
import numpy as np
3+
import pandas as pd
44

55

66
def create_dataframe():
77
"""Create Pandas DataFrame from local CSV."""
8-
df = pd.read_csv('data/311-calls.csv', parse_dates=['created'])
9-
df['created'] = df['created'].dt.date
10-
df.drop(columns=['incident_zip'], inplace=True)
11-
num_complaints = df['complaint_type'].value_counts()
8+
df = pd.read_csv("data/311-calls.csv", parse_dates=["created"])
9+
df["created"] = df["created"].dt.date
10+
df.drop(columns=["incident_zip"], inplace=True)
11+
num_complaints = df["complaint_type"].value_counts()
1212
to_remove = num_complaints[num_complaints <= 30].index
1313
df.replace(to_remove, np.nan, inplace=True)
1414
return df

plotlyflask_tutorial/plotlydash/layout.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Plotly Dash HTML layout override."""
22

3-
html_layout = '''
3+
html_layout = """
44
<!DOCTYPE html>
55
<html>
66
<head>
@@ -28,4 +28,4 @@
2828
</footer>
2929
</body>
3030
</html>
31-
'''
31+
"""

0 commit comments

Comments
 (0)