-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp2.py
49 lines (39 loc) · 1.17 KB
/
app2.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
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import plotly_express as px
import pandas as pd
df = pd.read_csv('homicides.csv')
app = dash.Dash(__name__)
opts = [ dict(label=t, value=t)
for t in df['Type'].unique() ]
app.layout = html.Div(
[dcc.Markdown("""
# Homicides in Australia
Select homicide types from the dropdown menu.
"""),
dcc.Dropdown(id='select-type',
options=opts,
multi=True,
value='Total'),
dcc.Graph(id='graph')
])
@app.callback(Output('graph', 'figure'),
[Input('select-type', 'value')])
def make_figure(select_type):
select_type = select_type
if isinstance(select_type, list)
else [select_type]
fig = px.line(
df.loc[df['Type'].isin(select_type)],
x='Year',
y='Homicides',
color='Type',
line_dash='Type',
template='presentation',
category_orders={'Type': ['Total']},
)
return fig.update_traces(mode='lines+markers')
if __name__ == '__main__':
app.run_server(debug=True)