The Palos Publishing Company

Follow Us On The X Platform @PalosPublishing
Categories We Write About

Create a Python dashboard for budgeting

Creating a Python dashboard for budgeting typically involves using libraries like Dash by Plotly, Streamlit, or Panel to create interactive web apps, combined with data handling libraries like Pandas. Here’s a straightforward example of a budgeting dashboard using Dash that lets you input budget categories and expenses, then visualizes the data.


python
import dash from dash import dcc, html, Input, Output, State import pandas as pd import plotly.express as px # Initialize the Dash app app = dash.Dash(__name__) app.title = "Budget Dashboard" # Sample initial budget data initial_data = { "Category": ["Rent", "Food", "Transport", "Entertainment", "Savings"], "Budgeted": [1200, 400, 150, 200, 300], "Spent": [0, 0, 0, 0, 0] } df = pd.DataFrame(initial_data) # App layout app.layout = html.Div([ html.H1("Personal Budget Dashboard", style={'textAlign': 'center'}), # Table showing budget and expenses html.Div(id='budget-table'), # Input fields to add/update expenses html.Div([ html.Label("Category:"), dcc.Dropdown( id='category-dropdown', options=[{'label': cat, 'value': cat} for cat in df['Category']], value='Food', clearable=False, style={'width': '200px'} ), html.Label("Amount Spent:"), dcc.Input(id='amount-input', type='number', min=0, step=0.01, value=0), html.Button('Add Expense', id='add-expense-btn', n_clicks=0) ], style={'marginTop': '20px'}), # Graph showing budget vs spent dcc.Graph(id='budget-graph'), # Store data in hidden div to keep state between callbacks dcc.Store(id='budget-data', data=df.to_dict('records')) ]) # Callback to update the table and graph whenever data changes @app.callback( Output('budget-table', 'children'), Output('budget-graph', 'figure'), Output('budget-data', 'data'), Input('add-expense-btn', 'n_clicks'), State('category-dropdown', 'value'), State('amount-input', 'value'), State('budget-data', 'data') ) def update_budget(n_clicks, category, amount, data): if n_clicks > 0 and amount is not None: df = pd.DataFrame(data) # Update the 'Spent' value for the selected category df.loc[df['Category'] == category, 'Spent'] += amount else: df = pd.DataFrame(data) # Create a simple table table = html.Table([ html.Thead([ html.Tr([html.Th(col) for col in df.columns]) ]), html.Tbody([ html.Tr([ html.Td(df.iloc[i][col]) for col in df.columns ]) for i in range(len(df)) ]) ], style={'width': '50%', 'margin': 'auto', 'border': '1px solid black', 'borderCollapse': 'collapse', 'textAlign': 'center'}) # Create bar chart comparing budgeted vs spent fig = px.bar(df, x='Category', y=['Budgeted', 'Spent'], barmode='group', title="Budgeted vs Spent per Category", labels={"value": "Amount ($)", "Category": "Budget Category"}) return table, fig, df.to_dict('records') if __name__ == '__main__': app.run_server(debug=True)

How this works:

  • The dashboard starts with predefined budget categories and budgeted amounts.

  • You select a category and enter the amount spent, then click Add Expense to update spending.

  • The table shows updated spending per category.

  • A bar chart dynamically compares budgeted vs spent amounts.


To run this:

  1. Install necessary libraries:

bash
pip install dash pandas plotly
  1. Save the code to a .py file (e.g., budget_dashboard.py) and run it:

bash
python budget_dashboard.py
  1. Open the local URL Dash outputs (usually http://127.0.0.1:8050) in your browser.


If you want, I can help you extend this with more features like monthly breakdowns, savings goals, or exporting data.

Share this Page your favorite way: Click any app below to share.

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Categories We Write About