# 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
df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/refs/heads/master/311_Animals_short.csv")
fig = px.scatter_map(df, lat="Latitude", lon="Longitude", color="Complaint Type",
color_continuous_scale=px.colors.cyclical.IceFire, size_max=15, zoom=10)
df['Count'] = df.groupby(['Borough', 'Complaint Type'])['Unique Key'].transform(lambda x: x.count())
#fig.show()
fig1 = px.treemap(df, path=[px.Constant("all"), 'Community Board', 'Complaint Type'],
values='Count', color='Complaint Type', color_discrete_map={'(?)':'lightgrey', 'Animal-Abuse':'red', 'Dead Animal':'orange'}, height=2000)
fig1.update_layout(margin = dict(t=50, l=25, r=25, b=25))
#fig1.show()
app = Dash(__name__)
md = """
# 311 Animal Complaints NYC
"""
app.layout = html.Div(
children=[
dcc.Markdown(children=md, link_target="_blank"),
dcc.Dropdown(id="dropdown", options=["red", "green", "blue", "orange"]),
dcc.Markdown(id="markdown", children=["## Scatter Map by Borough, Color coded by type of Complaint"]),
dcc.Graph(figure = fig),
dcc.Markdown(id="markdown1", children=["## TreeMap by Community Board, Color coded by type of Complaint Type and their count"]),
dcc.Graph(figure = fig1)
]
)
@callback(
Output("markdown", "style"),
Input("dropdown", "value"),
)
def update_markdown_style(color):
return {"color": color}