Baking Data Apps Into Raspberry Pi

In an earlier blogpost, we looked at why Docker is such an indispensable tool in the developer or data scientist’s toolkit, especially for shipping code that runs consistently across different environments. The Raspberry Pi, with its ARM architecture, provides a great example. Running software developed in traditional x86 environments on the Raspberry Pi can be challenging. Docker helps surmount these challenges and saves us endless frustration.

Show Me The Money Expense-Tracking App

I recently built an app for tracking expenses, particularly when my kid spent too much money on Zomato, a food delivery app! The idea was to set a monthly budget and track expenses against it. Visualizing data is crucial for self-adjustment on the path to improvement. The expense tracking system I built allows tracking expenses in common categories such as groceries, restaurants, utilities, etc.

The UI in PyQt6 for CRUD operations on Postgres warehouse. The MVC has Python with business objects in Pydantic and the SQLAlchemy ORM.
The expenses are managed through the app with a PyQt6 app that has a Postgres backend. The user can create a new expense, retrieve it for viewing, update it and apply changes or delete it. The Python implementation uses PyQt6 for UI and Pydantic for business objects with SQLAlchemy ORM.

I developed the app in the Python programming language. The app’s GUI, built in PyQt6, supports CRUD operations on a Postgres database. Users can create, view, update, and delete expenses. The architecture is a standard MVC framework with Pydantic business objects and SQLAlchemy ORM

Additionally, I built a dashboard in Grafana, a browser-based dashboarding tool. I developed the app on my MacBook and deployed it on the “always on” Raspberry Pi 400 at home.

Eat Humble Pie Code portability issues

I encountered many hurdles when porting code to the Raspberry Pi. The PyQt6 library couldn’t be installed in a virtual environment using the pip installer, so I installed it system-wide from the Debian repository. This prevented running my Python code in the virtual environment. Consequently, other dependencies like Pydantic and SQLAlchemy also had to be installed system-wide.

I built an expense tracking application to monitor day-day expenses and generate informative summaries. I used Grafana to construct a dashboard featuring interactive visualizations.
Get Grafana on Raspberry Pi. Build and share interactive visualizations.

I pulled the official Docker image for Postgres to get the database running. See this blogpost. However, finding a suitable SQL client was surprisingly difficult. I tried TablePlus, DBeaver, and Pgdmin, but each had issues post-installation, rendering them unusable.

A bad workman always blames his tools. Was I using the wrong tools or is the Raspberry Pi just Rubbish Pi?

It's Raining Containers Containerize the asset

The Raspberry Pi, being resource-constrained compared to a desktop, poses challenges in installing and running software. Docker can be invaluable in such situations. I was already running Postgres in a Docker container on the Raspberry Pi and found ARM-compatible containers for Pgadmin and Grafana. The pgAdmin container, provided by Elestio, is available as elestio/pgadmin.

Here’s how to install it:

  1. Pull the image: docker pull elestio/pgadmin
  2. Run the container:
	docker run --name pgadmin_service \
	-d -p 8080:8080 \
	--network docker-net \
	-e \
	-v ~/path/to/pgadmin/servers.json:/pgadmin4/servers.json \

This command starts a Pgadmin container named pgadmin_service in the background, accessible via http://localhost:8080, connected to the docker-net network, using the specified email and password for initial login credentials, and mounting a servers.json file for predefined server connections.

Don't Dally, Do Docker  Summary

Using Docker images for Pgadmin and Postgres provided a smooth path to setting up these vital data assets on my Raspberry Pi. This approach should generally be the default for installing software in app development. For example, when building home automation systems, it’s beneficial to containerize services like Mosquito MQTT, Node-Red, InfluxDB, and Grafana that are part of developer’s IoT stack. Refer to this YouTube video for a guide. For managing all these containers with a graphical UI, use Portainer, available as a free community edition from Docker. 

Unlock the full potential of AI with our FastAI course, where you’ll not only master AI integration into applications but also gain essential skills like Docker, crucial for deploying and managing your apps in real-world environments. Learn to bridge the gap between development and practical implementation, ensuring your AI solutions are robust, scalable, and ready for end-users. Join us to transform your technical expertise into powerful, customer-ready applications.