-
Notifications
You must be signed in to change notification settings - Fork 5
/
10) dash_layout.py
50 lines (38 loc) · 1.08 KB
/
10) dash_layout.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
43
44
45
46
47
48
49
50
# Import required packages
import pandas as pd
import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.express as px
from dash.dependencies import Input, Output
# Add Dataframe
df = pd.DataFrame({
"Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
"Amount": [4, 1, 2, 2, 4, 5],
"City": ["SF", "SF", "SF", "NYC", "MTL", "NYC"]
})
# Add a bar graph figure
fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")
app = dash.Dash()
# Create Layout
app.layout = html.Div(children=[
html.H1(
children='Dashboard',
style={
'textAlign': 'center'
}
),
# Create dropdown
dcc.Dropdown(options=[
{'label': 'New York City', 'value': 'NYC'},
{'label': u'Montréal', 'value': 'MTL'},
{'label': 'San Francisco', 'value': 'SF'}
],
value='NYC' # Providing a vallue to dropdown
),
# Bar graph
dcc.Graph(id='example-graph-2',figure=fig)
])
# Run Application
if __name__ == '__main__':
app.run_server()