-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathapp.py
More file actions
107 lines (84 loc) · 2.83 KB
/
Copy pathapp.py
File metadata and controls
107 lines (84 loc) · 2.83 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Feb 1 11:02:59 2019
@author: divyachandran
"""
import dash
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd
import plotly.graph_objs as go
df = pd.read_csv(
'https://gist.githubusercontent.com/chriddyp/'
'c78bf172206ce24f77d6363a2d754b59/raw/'
'c353e8ef842413cae56ae3920b8fd78468aa4cb2/'
'usa-agricultural-exports-2011.csv')
app = dash.Dash(__name__)
app.layout = html.Div([
html.H1("Food Product Exports in the United States", style={"textAlign": "center"}),
html.Div([
html.Div([
dcc.Dropdown(
id='product-selected1',
options=[{'label': i.title(), 'value': i} for i in df.columns.values[2:]],
value="poultry")], className="six columns", style={"width": "40%", "float": "right"}),
html.Div([
dcc.Dropdown(
id='product-selected2',
options=[{'label': i.title(), 'value': i} for i in df.columns.values[2:]],
value='beef')], className="six columns", style={"width": "40%", "float": "left"}),
], className="row", style={"padding": 50, "width": "60%", "margin-left": "auto", "margin-right": "auto"}),
dcc.Graph(id='my-graph')
], className="container")
@app.callback(
dash.dependencies.Output('my-graph', 'figure'),
[dash.dependencies.Input('product-selected1', 'value'),
dash.dependencies.Input('product-selected2', 'value')])
def update_graph(selected_product1, selected_product2):
dff = df[(df[selected_product1] >= 2) & (df[selected_product2] >= 2)]
trace1 = go.Bar(
x=dff['state'],
y=dff[selected_product1],
name=selected_product1.title(),
marker={
}
)
trace2 = go.Bar(
x=dff['state'],
y=dff[selected_product2],
name=selected_product2.title(),
marker={
}
)
return {
'data': [trace1, trace2],
'layout': go.Layout(
title=f'State vs Export: {selected_product1.title()}, {selected_product2.title()}',
colorway=["#EF963B", "#EF533B"],
hovermode="closest",
xaxis={
'title': "State",
'titlefont': {
'color': 'black',
'size': 14},
'tickfont': {
'size': 9,
'color': 'black'
}
},
yaxis={
'title': "Export price (million USD)",
'titlefont': {
'color': 'black',
'size': 14,
},
'tickfont': {
'color': 'black'
}
}
)
}
server = app.server
if __name__ == '__main__':
app.run_server(debug=True)