-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample4.py
More file actions
64 lines (54 loc) · 1.65 KB
/
example4.py
File metadata and controls
64 lines (54 loc) · 1.65 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
import pandas as pd
from dash import dcc, html, Dash
from dash.dependencies import Input, Output
df = pd.read_csv("bike-accidents.csv")
app = Dash(__name__)
districts = [{"label": district, "value": district} for district in df["DISTRITO"].unique()]
kinds_of_accidents = [{"label": kind, "value": kind} for kind in df["TIPO ACCIDENTE"].unique()]
app.layout = html.Div(children = [
html.H1("Bicimad accidents by district"),
html.H2("District"),
dcc.Dropdown(
id="district",
options=districts,
multi=True,
value=[districts[0]["value"]]
),
html.H2("Kind of accident"),
dcc.Dropdown(
id="kind_of_accident",
options=kinds_of_accidents
),
html.H2("kind of accident"),
dcc.Graph(
id="accidents-graph",
figure={
"data": [],
"layout": {
"title": "accidents"
}
}
)
])
xs = list(sorted(df["HORA"].unique()))
@app.callback(
Output(component_id="accidents-graph",component_property="figure"),
[
Input(component_id="district", component_property="value"),
Input(component_id="kind_of_accident", component_property="value")
]
)
def update(districts, kind_of_accident):
data = []
filtered_df = df[df["TIPO ACCIDENTE"] == kind_of_accident]
for district in districts:
count = filtered_df[filtered_df["DISTRITO"] == district]["HORA"].count()
row = {'x': list(range(0, 100)), 'y': [count], 'type': 'bar', 'name': district}
data.append(row)
return {
"data": data,
"layout": {
"title": "accidents"
}
}
app.run_server(debug=True)