# check out https://dash.plotly.com/ for documentation
# And check out https://py.cafe/maartenbreddels for more examples
from dash import Dash, Input, Output, callback, dcc, html
import pandas as pd
import plotly.express as px
## Variable pointing to github repo with raw CSV data ##
raw_github_url = "https://raw.githubusercontent.com/jragh/plotlymeetup/refs/heads/main/July_2025/Motor_Vehicle_Collisions_with_KSI_Data.csv"
## Dataframe creation from CSV url ##
df = pd.read_csv(raw_github_url)
## Dataframe Cleaning: Replacing None Values ##
df_cleaned = df.dropna(subset=["ACCNUM"])
df_cleaned = df_cleaned.loc[df_cleaned['ACCIDENT_YEAR'] >= 2020].copy().reset_index()
## Quick Group by for our first chart ##
## Also adding in the color based on the accident class ##
fig = px.bar(
df_cleaned.groupby(["ACCIDENT_YEAR", "ACCLASS"])["ACCNUM"].count().reset_index(),
x="ACCIDENT_YEAR",
y="ACCNUM",
color="ACCLASS",
barmode="stack"
)
## Server ##
app = Dash(__name__)
## Updating the layout for the served html ##
app.layout = html.Div(
children=[
dcc.Graph(figure=fig)
]
)