ivancho523 / sample-flask-charts-js

Flask Charts - Flask-RestX and Charts.JS | AppSeed

Home Page:https://blog.appseed.us/flask-charts-js-and-flask-restx-s92/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sample project crafted with Flask, Charts.JS, and Flask-RestX to showcase how to plot different charts Pie, Line and Bar Charts. Frontend uses Bootstrap5 for styling and Chart.js for dynamic charts. The dataset is loaded via a custom Flask CLI and the project homepage showcases three charts type: line, bar and pie.



Features:

  • Up-to-date dependencies
  • Stack: Flask
  • API: Flask-RestX
  • DB Tools: Flask-SqlAlchemy, SQLite
  • Charts: Charts.js

Flask Charts via Flask-RestX and Charts.js - provided by AppSeed.us

✨ How to use it

πŸ‘‰ Clone Sources (this repo)

$ git clone https://github.com/app-generator/blog-sample-flask-charts.git
$ cd blog-sample-flask-charts

πŸ‘‰ Install Modules using a Virtual Environment

$ virtualenv env
$ source env/bin/activate
$ pip3 install -r requirements.txt

Or for Windows-based Systems

$ virtualenv env
$ .\env\Scripts\activate
$
$ # Install modules - SQLite Database
$ pip3 install -r requirements.txt

πŸ‘‰ Set up the environment

$ export FLASK_APP=app.py
$ export FLASK_ENV=development

Or for Windows-based Systems

$ # CMD terminal
$ set FLASK_APP=app.py
$ set FLASK_ENV=development
$
$ # Powershell
$ $env:FLASK_APP = ".\app.py"
$ $env:FLASK_ENV = "development"

πŸ‘‰ Load Sample Data from data directory

  • monthly_customers.csv
  • monthly_sales.csv
  • product_sales.csv
$ flask load-data 

πŸ‘‰ Start the APP

$ flask run 

✨ Code-base structure

< PROJECT ROOT >
   |
   |-- app.py            # Create and start the APP object
   |-- api.py            # Simple API node 
   |-- models.py         # app models
   |
   |-- data_loader.py    # Save the data in DB
   |
   |-- templates
   |    |-- index.html   # Simple page styled with BS5 
   |
   |-- static
   |    |-- js/custom.js # Code the Charts
   |
   |-- *******************

The bootstrap flow

  • app.py
    • bundles all resources
    • serve the index.html
  • api.py exposes a simple API using the DB data
  • templates/index.html
    • HOMEpage of the project
  • js/custom.js
    • fetch data exposed by the API


Flask Charts via Flask-RestX - provided by AppSeed

About

Flask Charts - Flask-RestX and Charts.JS | AppSeed

https://blog.appseed.us/flask-charts-js-and-flask-restx-s92/

License:MIT License


Languages

Language:JavaScript 43.3%Language:Python 40.6%Language:HTML 16.0%