Balance
Part of the Piggybank
Income: **€ :sum[be]{path="income" field="amount"}** · Spending: **€ :sum[bu]{path="expenses" field="amount"}**
data space «casa-en» — this micro app reads and writes the suite’s shared data space.
The other micro apps in the same suite
How it works
This is a Reactive app: a plain text document that your browser turns into a working app — forms, live data, tables, statistics and even charts, with nothing to install or configure.
- Use it right away. Hit “Use this app”: it opens right in your browser, ready to go, with data saved only on your device.
- Your data stays yours. Everything is stored locally on your device, kept separate for each app: no account, no server, nothing to set up.
- Make it your own. The text below is the entire app: copy it, tweak fields, views and words, and your changes become interactive instantly.
- Share it as a file. An app is a simple file: save it, export it or share it with a link; and with encrypted collaboration several people edit the same data in real time.
The app’s source
# 📊 Balance
## How we are doing
Income: **€ :sum[be]{path="income" field="amount"}** ·
Spending: **€ :sum[bu]{path="expenses" field="amount"}**
:::python{data="expenses,income" packages="matplotlib"}
```
import matplotlib.pyplot as plt
expenses = data.get("expenses", [])
income = data.get("income", [])
tot_out = sum(float(r.get("amount", 0) or 0) for r in expenses)
tot_in = sum(float(r.get("amount", 0) or 0) for r in income)
print(f"Balance: € {tot_in - tot_out:.2f}")
if expenses:
percat = {}
for r in expenses:
c = r.get("category") or "Other"
percat[c] = percat.get(c, 0) + float(r.get("amount", 0) or 0)
fig, ax = plt.subplots(figsize=(6, 3.2))
ax.bar(list(percat.keys()), list(percat.values()))
ax.set_ylabel("€")
ax.set_title("Spending by category")
plt.xticks(rotation=20)
plt.tight_layout()
else:
print("Add a few expenses to see the chart by category.")
```
:::