TLDR: Just change your .sum()
in plot_collisions_bar()
to .sum(numeric_only=True)
For details, the modified plot_collisions_bar()
is listed below:
@app.callback(Output("graph", "figure"),
[Input("date picker", "start_date"),
Input("date picker", "end_date"),])
def plot_collisions_bar(start_date, end_date):
fig = px.bar(
(collisions
.loc[collisions["DATE"].between(start_date, end_date)]
.groupby("BOROUGH", as_index=False)
.sum(numeric_only=True) # <<< Change here
)
,
x="COLLISIONS",
y="BOROUGH",
title=f"Traffic Acci[![enter image description here][1]][1]dents in NYC between {start_date[:10]} and {end_date[:10]}"
)
return fig