Skip to content

Commit c3c749f

Browse files
committed
Minor cleanup.
1 parent aeaf009 commit c3c749f

File tree

11 files changed

+44
-52
lines changed

11 files changed

+44
-52
lines changed

application/__init__.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
1-
"""Initialize app."""
1+
"""Initialize Flask app."""
22
from flask import Flask
33

44

55
def create_app():
6-
"""Construct the core application."""
7-
app = Flask(__name__,
8-
instance_relative_config=False)
6+
"""Construct core Flask application with embedded Dash app."""
7+
app = Flask(__name__, instance_relative_config=False)
98
app.config.from_object('config.Config')
109

1110
with app.app_context():
12-
13-
# Import main Blueprint
11+
# Import Flask routes
1412
from application import routes
15-
app.register_blueprint(routes.main_bp)
1613

1714
# Import Dash application
1815
from application.plotlydash.dashboard import create_dashboard
1916
app = create_dashboard(app)
2017

21-
# Compile assets
18+
# Compile CSS
2219
from application.assets import compile_assets
2320
compile_assets(app)
2421

application/assets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
def compile_assets(app):
5-
"""Configure authorization asset bundles."""
5+
"""Compile stylesheets if `app` is running in development mode."""
66
assets = Environment(app)
77
Environment.auto_build = True
88
Environment.debug = False
Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,31 @@
1-
"""Create a Dash app within a Flask app."""
1+
"""Instantiate a Dash app."""
2+
import numpy as np
3+
import pandas as pd
24
import dash
35
import dash_table
46
import dash_html_components as html
57
import dash_core_components as dcc
6-
import plotly.graph_objects as go
7-
import pandas as pd
8-
import numpy as np
98
from .layout import html_layout
109

1110

1211
def create_dashboard(server):
13-
"""Create a Dash app."""
14-
external_stylesheets = ['/static/dist/css/styles.css',
15-
'https://fonts.googleapis.com/css?family=Lato',
16-
'https://use.fontawesome.com/releases/v5.8.1/css/all.css']
12+
"""Create a Plotly Dash dashboard."""
1713
dash_app = dash.Dash(server=server,
18-
external_stylesheets=external_stylesheets,
19-
external_scripts=external_scripts,
20-
routes_pathname_prefix='/dashapp/')
14+
routes_pathname_prefix='/dashapp/',
15+
external_stylesheets=['/static/dist/css/styles.css',
16+
'https://fonts.googleapis.com/css?family=Lato']
17+
)
2118

2219
# Prepare a DataFrame
23-
df = pd.read_csv('data/311-calls.csv')
20+
df = pd.read_csv('data/311-calls.csv', parse_dates=['created_date'])
2421
num_complaints = df['complaint_type'].value_counts()
2522
to_remove = num_complaints[num_complaints <= 20].index
2623
df.replace(to_remove, np.nan, inplace=True)
2724

28-
# Override the underlying HTML template
25+
# Custom HTML layout
2926
dash_app.index_string = html_layout
3027

31-
# Create Dash Layout comprised of Data Tables
28+
# Create Layout
3229
dash_app.layout = html.Div(
3330
children=[dcc.Graph(
3431
id='histogram-graph',
@@ -52,18 +49,17 @@ def create_dashboard(server):
5249
],
5350
id='dash-container'
5451
)
55-
5652
return dash_app.server
5753

5854

5955
def create_data_table(df):
60-
"""Create table from Pandas DataFrame."""
61-
table_preview = dash_table.DataTable(
56+
"""Create Dash datatable from Pandas DataFrame."""
57+
table = dash_table.DataTable(
6258
id='database-table',
6359
columns=[{"name": i, "id": i} for i in df.columns],
6460
data=df.to_dict('records'),
6561
sort_action="native",
6662
sort_mode='native',
6763
page_size=300
6864
)
69-
return table_preview
65+
return table

application/routes.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
"""Core Flask app routes."""
2-
from flask import Blueprint, render_template
2+
from flask import render_template
33
from flask import current_app as app
44

55

6-
main_bp = Blueprint('main_bp', __name__,
7-
template_folder='templates',
8-
static_folder='static')
9-
10-
11-
@main_bp.route('/')
6+
@app.route('/')
127
def home():
138
"""Landing page."""
149
return render_template('index.jinja2',

application/static/dist/css/styles.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

application/static/dist/js/includes/jquery.min.js

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

application/static/dist/js/main.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

application/static/less/global.less

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ html {
44
margin: 0;
55
padding: 0;
66
background: #e7ecf7 !important;
7-
background: #edf4f7;
8-
font-family: 'Lato';
7+
font-family: 'Lato', sans-serif;
98
}
109

1110
.row .col {

application/static/less/header.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ header {
44
padding: 30px 0 !important;
55
background: white!important;
66
box-shadow: 0 0 5px #bec6cf;
7-
font-family: 'Lato',sans-serif;
7+
font-family: 'Lato', sans-serif;
88

99
.nav-wrapper {
1010
display: flex;

application/static/less/home.less

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
.home-template {
22
.container {
3-
width: 1000px;
4-
margin: 50px auto;
3+
margin: 0 !important;
54
}
65

76
.card {
8-
width: 900px;
7+
width: 800px;
98
max-width: 93%;
109
height: fit-content;
11-
margin: 40px auto 0;
12-
padding: 50px;
10+
margin: 50px auto;
11+
padding: 60px;
1312
background: white;
14-
box-shadow: 0 0 5px rgba(65, 67, 144, 0.15);
13+
box-shadow: 0 0 5px rgba(65,67,144,0.15);
1514
text-align: center;
1615
@media (max-width: 800px) {
16+
max-width: 78%;
1717
width: unset;
18-
padding: 40px 0;
18+
padding: 40px;
1919
}
2020

2121
.logo {
@@ -24,7 +24,7 @@
2424
}
2525

2626
.site-title {
27-
margin: 20px 0 3px;
27+
margin: 10px 0 3px;
2828
color: #5f6988;
2929
font-family: proxima-nova, sans-serif;
3030
font-size: 2.3em;
@@ -51,6 +51,10 @@
5151
font-size: 1.1em;
5252
font-weight: 600;
5353

54+
&:hover {
55+
opacity: .7;
56+
}
57+
5458
i {
5559
margin-left: 6px;
5660
font-size: .9em;

0 commit comments

Comments
 (0)