# check out https://dash.plotly.com/ for Dash documentation
# check out https://plotly.com/python for Plotly documentation
# check out Plotly High Level refernece docs: https://plotly.com/python-api-reference/plotly.express.html
# Plotly Studio sign-up: https://docs.google.com/spreadsheets/d/1Z4DVKKXIeFOpe6mOfBGN5QAdYeJrW4X2mKT1UlxeYDE/edit?usp=sharing
# Adam's LinkedIn: https://www.linkedin.com/in/charming-data/
from dash import Dash, Input, Output, callback, dcc, html
import dash_ag_grid as dag
import pandas as pd
import plotly.express as px
# Download data (Github): https://github.com/plotly/datasets/blob/master/2018_Central_Park_Squirrel_Census_-_Squirrel_Data_20250721.csv
# Downlaod data (NYC portal): https://data.cityofnewyork.us/Environment/2018-Central-Park-Squirrel-Census-Squirrel-Data/vfnx-vebw/about_data
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/refs/heads/master/2018_Central_Park_Squirrel_Census_-_Squirrel_Data_20250721.csv')
"""
Use this sectiont to slice, clean, filter data to prepare it for the figure
"""
daily_counts_shift = df.groupby("Shift").size().reset_index(name="Count")
# Build the figure
fig_pie = px.pie(
daily_counts_shift,
names="Shift",
values="Count",
title="Daily Sightings by Shift",
labels={"Count": "Number of Sightings", "Shift": "Shift"}
)
df['Date'] = pd.to_datetime(df['Date'].astype(str), format='%m%d%Y')
grid = dag.AgGrid(
rowData=df.to_dict("records"),
columnDefs=[{"field": i, 'filter': True, 'sortable': True} for i in df.columns],
dashGridOptions={"pagination": True},
# columnSize="sizeToFit"
)
daily_count = df.groupby("Date").size().reset_index(name="Count")
# Build the figure
fig_bar = px.bar(
daily_count,
x="Date",
y="Count",
title="",
labels={"Count": "Number of Sightings", "Date": "Date"}
)
app = Dash()
app.layout = html.Div([
grid,
dcc.Graph(figure=fig_pie),
dcc.Graph(figure=fig_bar)
])
# Plotly Studio sample -- https://centralparksquirrels.plotly.app