Connecting Streamlit
In this article, we will walk through the process of building a dashboard using Streamlit. To make it more illustrative, we will create a dashboard that connects to the analytical database and monitors the real-time status of vehicles.
Dashboard features
Display total number of objects
Visualize movement statuses (moving/stopped/parked)
Visualize connection statuses (active/idle/offline)
Detailed table with current status of all vehicles
Filtering by vehicle type, group, movement status, and connection status
Automatic data refresh every 5 minutes
Toggle between light and dark themes
Technical requirements
Python 3.8+
Internet access for database connection
Minimum 2 GB RAM
Installation and setup
1. Clone the repository
2. Create a virtual environment
Make sure you have Python 3.8 or higher installed. You can check the version with the command python --version.
3. Install dependencies
After activating the virtual environment, install all necessary libraries:
Database connection
1. Create a configuration file
Create a .env file in the project's root directory:
Connection parameter reference
Host
DB_HOST in .env file
The database server address provided in your welcome email
Port
DB_PORT in .env file
Default is 5432 for PostgreSQL
Database name
DB_NAME in .env file
Your assigned database name
Username
DB_USER in .env file
Your database username
Password
DB_PASS in .env file
Your secure database password
SSL mode
Connection string in Python code
Set to require in the connection string
Schema
DB_SCHEMA in .env file
Specify schema (raw_business_data or raw_telematics_data)
2. Obtaining credentials
Request credentials for connecting to the demonstration database by contacting the administrator.
Running the dashboard
After setting up the database connection, start the dashboard with the command:
After launching, you'll see a message similar to:
Open the specified URL in your browser. The dashboard will be available at http://localhost:8501 (or at the network URL if you want to open it from another device on the network).
Developing custom components
If you want to modify the dashboard or create new components:
1. Modifying the existing dashboard
Streamlit automatically reloads the application when you change the source code. Simply edit the moving_status_dashboard.py file and save your changes.
2. Adding new visualizations
To add new charts and diagrams, use libraries:
Plotly:
import plotly.express as pxorimport plotly.graph_objects as goBuilt-in Streamlit visualizations:
st.bar_chart(),st.line_chart(), etc.
Example of adding a new chart:
3. Debugging
For debugging, use
Troubleshooting
Database connection issues
Connection error: Check the correctness of credentials in the
.envfile and database availabilitySSL error: Make sure your IP is on the allowlist for database access
Timeout errors: Check your internet connection stability and firewall settings
Dependency issues
Error installing psycopg2-binary:
Windows:
pip install pipwin && pipwin install psycopg2-binaryLinux:
sudo apt install python3-dev libpq-devmacOS:
brew install postgresql
Dependency conflicts:
Create a new virtual environment
Install dependencies one by one, starting with streamlit
Other issues
Here are some tricks that can help you fix common issues:
Update dependencies:
pip install -r requirements.txt --upgradeCheck Python compatibility:
python --version(should be 3.8+)When changing code, include debug messages:
Streamlit cache errors: stop the application and run with the
--clear_cacheflag:
Next steps
After successfully connecting Power BI to your Private Telematics Lakehouse instance, we recommend you to:
Explore the available data schemas by reviewing the Schema overview section to better understand the data structure and relationships.
Start with simple queries focused on specific business entities before building complex dashboards - check our example queries for reference.
Support
For technical questions or requests for access to the demonstration database, please contact: [email protected]
Last updated
Was this helpful?