import pandas as pd
import plotly.graph_objects as go
from dash import Dash, html, dcc
import requests
# Load cleaned budget data from GitHub
CSV_URL = "https://raw.githubusercontent.com/ProgInNameOnly/WakeCountyBudget/main/Budget_FY2023%20(1)_cleaned.csv"
df = pd.read_csv(CSV_URL)
# Filter for top 15 Cost Centers by total spend
top_centers = df.groupby("Cost_Center")["Actual_Amount"].sum().nlargest(15).index
filtered_df = df[df["Cost_Center"].isin(top_centers)]
# Group: Fund_Name ➝ Cost_Center
grouped = filtered_df.groupby(["Fund_Name", "Cost_Center"])["Actual_Amount"].sum().reset_index()
# Build label list
labels = pd.concat([grouped["Fund_Name"], grouped["Cost_Center"]]).unique().tolist()
label_index = {label: idx for idx, label in enumerate(labels)}
# Sankey source/target/value
source = grouped["Fund_Name"].map(label_index).tolist()
target = grouped["Cost_Center"].map(label_index).tolist()
value = grouped["Actual_Amount"].tolist()
# Build Sankey
fig = go.Figure(go.Sankey(
node=dict(
pad=15,
thickness=20,
line=dict(color="black", width=0.5),
label=labels,
),
link=dict(
source=source,
target=target,
value=value
)
))
fig.update_layout(title_text="Wake County Budget FY2023: Top 15 Cost Centers", font_size=12)
# Dash app layout
app = Dash(__name__)
app.layout = html.Div([
html.H2("💰 Wake County Budget FY2023: Fund ➝ Top 15 Cost Centers", style={"textAlign": "center"}),
dcc.Graph(figure=fig)
])
# For PyCafe
if __name__ == "__main__":
app.run(debug=False, port=8050)