-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathapp.py
More file actions
66 lines (54 loc) · 1.87 KB
/
app.py
File metadata and controls
66 lines (54 loc) · 1.87 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.graph_objs as go
import pandas as pd
########### Define your variables ######
# here's the list of possible columns to choose from.
list_of_columns =['code', 'state', 'category', 'total exports', 'beef', 'pork', 'poultry',
'dairy', 'fruits fresh', 'fruits proc', 'total fruits', 'veggies fresh',
'veggies proc', 'total veggies', 'corn', 'wheat', 'cotton']
mycolumn='corn'
myheading1 = f"Wow! That's a lot of {mycolumn}!"
mygraphtitle = '2011 US Agriculture Exports by State'
mycolorscale = 'ylorrd' # Note: The error message will list possible color scales.
mycolorbartitle = "Millions USD"
tabtitle = 'Old McDonald'
sourceurl = 'https://plot.ly/python/choropleth-maps/'
githublink = 'https://github.com/austinlasseter/dash-map-usa-agriculture'
########## Set up the chart
import pandas as pd
df = pd.read_csv('assets/usa-2011-agriculture.csv')
fig = go.Figure(data=go.Choropleth(
locations=df['code'], # Spatial coordinates
z = df[mycolumn].astype(float), # Data to be color-coded
locationmode = 'USA-states', # set of locations match entries in `locations`
colorscale = mycolorscale,
colorbar_title = mycolorbartitle,
))
fig.update_layout(
title_text = mygraphtitle,
geo_scope='usa',
width=1200,
height=800
)
########### Initiate the app
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
server = app.server
app.title=tabtitle
########### Set up the layout
app.layout = html.Div(children=[
html.H1(myheading1),
dcc.Graph(
id='figure-1',
figure=fig
),
html.A('Code on Github', href=githublink),
html.Br(),
html.A("Data Source", href=sourceurl),
]
)
############ Deploy
if __name__ == '__main__':
app.run_server()