forked from danny-baker/dash-heroku
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
42 lines (30 loc) · 1.51 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from dash import Dash, callback, html, dcc
import dash_bootstrap_components as dbc
import numpy as np
import pandas as pd
import matplotlib as mpl
import gunicorn #whilst your local machine's webserver doesn't need this, Heroku's linux webserver (i.e. dyno) does. I.e. This is your HTTP server
from whitenoise import WhiteNoise #for serving static files on Heroku
# Instantiate dash app
app = Dash(__name__, external_stylesheets=[dbc.themes.FLATLY])
# Reference the underlying flask app (Used by gunicorn webserver in Heroku production deployment)
server = app.server
# Enable Whitenoise for serving static files from Heroku (the /static folder is seen as root by Heroku)
server.wsgi_app = WhiteNoise(server.wsgi_app, root='static/')
# Define Dash layout
def create_dash_layout(app):
# Set browser tab title
app.title = "Your app title"
# Header
header = html.Div([html.Br(), dcc.Markdown(""" # Hi. I'm your Dash app."""), html.Br()])
# Body
body = html.Div([dcc.Markdown(""" ## I'm ready to serve static files on Heroku. Just look at this! """), html.Br(), html.Img(src='charlie.png')])
# Footer
footer = html.Div([html.Br(), html.Br(), dcc.Markdown(""" ### Built with ![Image](heart.png) in Python using [Dash](https://plotly.com/dash/)""")])
# Assemble dash layout
app.layout = html.Div([header, body, footer])
return app
# Construct the dash layout
create_dash_layout(app)
# Run flask app
if __name__ == "__main__": app.run_server(debug=True)