-
Notifications
You must be signed in to change notification settings - Fork 0
3. Deployment to Heroku
The Belly Button Biodiversity dashboard was deployed using Heroku. At this point, the folder structure was already as follows:
Belly_Button_Biodiversity/
belly_button/
__init__.py
app.py
db/
bellybutton.sqlite
static/
css/
main.css
js/
app.js
templates/
index.html
initdb.py
Procfile
requirements.txt
run.sh
runtime.txt
The following dependencies were installed using pip install <dependency name>
via Terminal in the BellyButton virtual environment.
-
pandas
-
simplejson
-
sqlalchemy
-
flask
-
flask_sqlalchemy
-
psycopg2-binary (to access PostgreSQL, the default database of Heroku)
-
gunicorn (a Python Web Server Gateway Interface)
cd Belly_Button_Biodiversity source activate BellyButton pip install pandas pip install simplejson pip install sqlalchemy pip install flask pip install flask_sqlalchemy pip install psycopg2-binary pip install gunicorn
The file requirements.txt
contains the versions of the different libraries and programming languages that would be used in running the Belly Button dashboard. Before the dashboard's deployment, these versions had to be "frozen". This prevents a future or a past incompatible version from being used during the use of the dashboard.
pip freeze > requirements.txt
A text file named "Procfile" was created in the Belly_Button_Biodiversity folder.
touch Procfile
In the text editor (Virtual Studio in my case), the content of Procfile was edited such that the folder containing app.py
("belly_button") was indicated. This file allowed production mode testing of the dashboard's app.py
.
web: gunicorn belly_button.app:app
A text file called "runtime.txt" was created in the Belly_Button_Biodiversity folder.
touch runtime.txt
In the text editor, the Python version being used was indicated.
python-3.6.7
A shell file, called "run.sh" was created in the Belly_Button_Biodiversity folder.
touch run.sh
This file contains code that would automate running the Flask app which was found within the "belly_button" folder. It read thus, in the text editor:
FLASK_APP=belly_button/app.py flask run
The code was pre-tested in Python (in Terminal) in which Flask was run in the production within the virtual environment. the Python file initdb.py, which imported the database from app.py
, was run, followed by specifying that app.py
was inside the "belly_button" folder.
python initdb.py
FLASK_APP=belly_button/app.py
The directory 127.0.0.1:5000
was opened in Google Chrome incognito mode to prevent issues caused by cookies and by the search history. The interactive nature of the pie and the bubble charts were verified. Then, the incognito window was closed.
After logging into Heroku, the personal dashboard would appear. The New
button was clicked and then Create new app
was selected. In the next page, no information was submitted in the input fields; instead, the Create new app
was clicked again. the next page contained instructions on how to deploy using Heroku Git. After installing the Heroku CLI, the first step was to use Terminal to go to the project folder and to initiate Git. In this case,
cd Belly_Button_Biodiversity
git init
The rest of the instructions led towards the creation of a remote branch for Heroku, adding files, committing, and pushing onto the Heroku master.
Once deployment was successful, Heroku would provide the link to the website. In the case of the Belly Button dashboard, the link is: https://still-brook-99773.herokuapp.com/.