Your customer dashboard, clients, or their fellow workers are part of the skills set up by software developers, data scientists, ml, and data engineers. Or you work primarily on the process of base back, details you use frequently requires “surfaced” to users at a particular time. If you are lucky, your organization may have a previously dedicated team to take care of that, but often it will be down to you.
Being a straight Python Engineer without Experience in HTML, JavaScript, etc.
This text is not for them, however, because I am One of those people are straightforward, and I have already done a broadcast and gradio. So it was time to fold my sleeves and see if I could learn new skills and to create a Dashiboard and the old advanced development: HTML, Javascript, and CSS.
Our Dashboard details will appear in the SQLILE location database. I build a Sales_data Table in SQLITE containing dummy sales data. Here are the data in the form of tabar.
Photo by the writer
Below one code you can use to follow and create your SQLITE and table database and data as shown.
In case you wonder why I only add a few records to my database, it is not because I don't think the code can handle small data volumes. It is just that I wanted to focus on the dashboard performance rather than the data. Feel free to use the text I offer below to enter additional records input data if you like.
Therefore, we live in the Python of Nthon only long when we set a SQLITINE DB program in order.
import sqlite3
# Define the database name
DATABASE_NAME = "C:\Users\thoma\projects\my-dashboard\sales_data.db"
# Connect to SQLite database
conn = sqlite3.connect(DATABASE_NAME)
# Create a cursor object
cursor = conn.cursor()
# SQL to create the 'sales' table
create_table_query = '''
CREATE TABLE IF NOT EXISTS sales (
order_id INTEGER PRIMARY KEY,
order_date TEXT,
customer_id INTEGER,
customer_name TEXT,
product_id INTEGER,
product_names TEXT,
categories TEXT,
quantity INTEGER,
price REAL,
total REAL
);
'''
# Execute the query to create the table
cursor.execute(create_table_query)
# Sample data to insert into the 'sales' table
sample_data = [
(1, "2022-08-01", 245, "Customer_884", 201, "Smartphone", "Electronics", 3, 90.02, 270.06),
(2, "2022-02-19", 701, "Customer_1672", 205, "Printer", "Electronics", 6, 12.74, 76.44),
(3, "2017-01-01", 184, "Customer_21720", 208, "Notebook", "Stationery", 8, 48.35, 386.80),
(4, "2013-03-09", 275, "Customer_23770", 200, "Laptop", "Electronics", 3, 74.85, 224.55),
(5, "2022-04-23", 960, "Customer_23790", 210, "Cabinet", "Office", 6, 53.77, 322.62),
(6, "2019-07-10", 197, "Customer_25587", 202, "Desk", "Office", 3, 47.17, 141.51),
(7, "2014-11-12", 510, "Customer_6912", 204, "Monitor", "Electronics", 5, 22.5, 112.5),
(8, "2016-07-12", 150, "Customer_17761", 200, "Laptop", "Electronics", 9, 49.33, 443.97)
]
# SQL to insert data into the 'sales' table
insert_data_query = '''
INSERT INTO sales (order_id, order_date, customer_id, customer_name, product_id, product_names, categories, quantity, price, total)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
'''
# Insert the sample data
cursor.executemany(insert_data_query, sample_data)
# Commit the transaction
conn.commit()
# Close the connection
conn.close()
print(f"Database '{DATABASE_NAME}' has been created and populated successfully.")
Dashboard performance
Our dashboard will have the next function.
The main metrics. Currency, total orders, average order value, maximum class
Different types of chart. Time income (line chart), income in section (a bar chart), high products for income (horizontal of the Baries)
Sorting. Day and category
Data table. Demonstrate our data records in the paved and continuous grid.
To set our environment
Next, we have a series of steps that should be followed to set up our environment.
1 / Enter Node.js.
Node.js is a javaScript without browser, which allows you to use javascript to create a server's instant and server applications.
Therefore, make sure Node.js is included in your system so that it can use a local server and manage packages. You can pick up from the Node.JS official website.
2 / Create a main project folder and subfolders
Open your command terminal and run the following instructions. I use the personality in my Windows box in this, but you can change it to suit your preferred instruction system and program.
$ mkdir my-dashboard
$ cd my-dashboard
$ mkdir client
% mkdir server
3 / Start Node project
$ npm init -y
This command creates automatically automatic packet.json File to your project Directory without requiring user input.
This page – Flag responses “Yes” In all motions, you use Default prices For fields such as:
Sqlite Is the engine of a lack of lightness, based on files that keep your information from one, portable file, which ends the need for a different server.
Squeeze A small framework, the node.js variable enhances the construction of the APIs and web servers through the route and the MiddleWare.
We can include both using the command below.
$ npm install express sqlite3
Now, we can begin to improve our code. For this project, we will need four code files: Index Index.html File, the server.js file, the client file.js, and script.js file.
Let's exceed each of them by step by step.
1) Client / index.html
Sales Performance Dashboard
Key Metrics
This HTML file establishes the significant basic dashboard items, including applicable filters of the day and category, a category that shows key metrics, drop-up menu for selecting chart.
Bootstrap used to pull. Flatpickr used for a day's installation. Chart.j used for observation, and Tatanada is used for displaying. Interaction is handled by external Skric.js File, which will check soon.
The Bootstrap is a famous framework, which is made up of Twitter, helps you build a turning webpoint and immediately.
Data information is a plugin based on Jquery that improves common HTML
Things, transform them into full partners, rich tables.
Flatpickr is a lightweight, made of JavaScript wish and time to choose time. Allows users to select days (and selection times) in a Pop-up Butneed calendar instead of hand typing.
Chert.js is a simple but powerful JavaScript building to create active charts, animated in web applications using
We use the Cascading Style sheet (CSS) Style basic portions of our dashboard, for example, button and text colors, distinguishes between items, etc.
Type.csS file offers its dashboard and perfect looks. Today's pure, bright-colored content with the best conditions to distinguish spaces and clarity and readings. The style.css file is also customized appearance of Daginages 'butto' but easy-to-use and conforming to bootstrap shape.
3) server / server.js.js
const express = require('express');
const sqlite3 = require('sqlite3').verbose();
const path = require('path');
const app = express();
const PORT = 3000;
// Full path to your SQLite database
const DB_PATH = "C:\Users\thoma\projects\my-dashboard\sales_data.db";
// Serve static files from the client directory
app.use(express.static(path.join(__dirname, '..', 'client')));
// Route to fetch data from SQLite database
app.get('/data', (req, res) => {
const db = new sqlite3.Database(DB_PATH, sqlite3.OPEN_READONLY, (err) => {
if (err) {
console.error("Error connecting to database:", err.message);
res.status(500).json({ error: "Database connection failed" });
return;
}
});
// Query the database
const query = "SELECT * FROM sales;"; // Replace 'sales' with your table name
db.all(query, [], (err, rows) => {
if (err) {
console.error("Error running query:", err.message);
res.status(500).json({ error: "Query failed" });
} else {
res.json(rows); // Send the query result as JSON
}
});
db.close((err) => {
if (err) {
console.error("Error closing database:", err.message);
}
});
});
// Catch-all route to serve the main HTML file
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, '..', 'client', 'index.html'));
});
// Start the server
app.listen(PORT, () => {
console.log(`Server running at
});
This node.js script contains the JavaScript code that puts the basic Express server that enables the sales dashboard. It makes two advanced things:
You work for static files (such as HTML, CSS, and JS) from the client subfolder so the frontlend load in the browser.
It provides a / data Connections of the local SQLITE (Sales_Data.data.DB) and restore the entire sales table as JSON, allows powerful data recognition before.
4) Client / Script.js
let chartInstance = null; // Global variable to store the current Chart.js instance
// Wait until the DOM is fully loaded
document.addEventListener('DOMContentLoaded', function () {
// Fetch sales data from the backend API
fetch('/data')
.then((response) => response.json())
.then((data) => {
// Handle case where no data is returned
if (!data || data.length === 0) {
const app = document.getElementById('app');
if (app) {
app.innerHTML = "
I showed you how to create and express sqlite database details on the code we can use as our dashboard's resource data. We also discussed the seating of evolution and advanced development procedures and background programs, and briefly affects the functioning of our dashboard operations.
Finally, I passed and passed by described the detailed four code files we need to create, and show how to use the dashboard in the browser.
Looking at Data Science is a public book. Submit your information to access our worldwide audience and get through the TDS author billing program.
Write Tds
Related Scriptures
The three ordinary Python tricks make your system immediately, I will explain the methods
8 min learn
Our Church Selection is the selection of learned reading methods and real features
Let's get 8 years back in time
Repeating Lessons Learned by Cole Nussbaumer Ksaffic Book Eppython uses Mattplotlib
Use Python login as a pro
How to Use WebSockets to create real-time Apis on travel