This project demonstrates how to serve an Altair visualization using Flask. The application shows potential sites to implement a geothermal energy technology by re-purposing old wells. The user specifies the criteria for the wells and a plot is generated showing the location of those wells. One can deploy this app using a service like Heroku or just locally.
All required Python packages can be found in the requirements.txt
file. Since the project makes use of GNU Make, there is no need to directly create the environment. The creation and activation of the environment is handled by running the Make rules that are shown in later sections. If you do go the Make route, make sure you have Python Poetry installed.
The application uses an SQL database and makes queries against it to obtain the wells to visualize. Two options are presented: SQLite for only local deployment or PostgreSQL for either local or deployment to Heroku. Instructions for both are found below. Note, you can skip the last step of each and jump to deployment by running make all
, as running make all
takes care of creating the database once .env
has been configured properly. By default, create-db
truncates the records in the database to comply with Heroku's free tier limit. However, you can prevent truncation by setting the environmental variable TRUNCATE
to an empty string. E.g., make TRUNCATE="" all
.
- Create your own
.env
:cp .env.template .env
- Assign
URI_DB
tosqlite:///data/wells.db
- Run
make create-db
ormake TRUNCATE="" create-db
(no truncation)
- Create a Heroku account
- Install the Heroku CLI
- Create your own
.env
:cp .env.template .env
- Create a Heroku app:
heroku create
- In your
.env
, setAPP_NAME
to your application's name form the previous step - Run
make create-db
You can use a database that is not managed by Heroku. For example, your own Postgres server you have setup yourself or a fully managed one by a different provider. If you want to go the latter route, consider ElephantSQL. The free tier lets you have a database up to 20 MB. Whatever you decide, the instructions are similiar, run make create-db
. However, before you run make create-db
, make sure you add export OTHER_DB=true
to your .env
.
Two things to consider:
-
If you are deploying to Heroku, make sure you set
APP_NAME
asmake create-db
will set theURI_DB
environmental variable on Heroku. If you don't setAPP_NAME
, you will need to make sure you setURI_DB
on Heroku yourself. -
If you are using a different RDBMS, e.g., MySQL, you'll need to make sure you have the appropriate Python driver installed in your virtual environment.
Now that you have the SQL database has been created and .env
configured properly, you are ready to deploy locally or to Heroku.
To deploy the app locally, simply run make deploy
. It will use whatever database is specified in URI_DB
in .env
.
To deploy the app to Heroku:
bin/set_secret_key
git push heroku master
heroku open
You can deploy and run the application locally using Docker. After creating a database, you can run make docker-run
or:
docker build -t flask_app .
docker run --init --rm -d --publish 127.0.0.1:5000:5000 flask_app
Once running, visit localhost:5000
on your web browser. As with other methods, you need to make sure you've created your database and properly configured your .env.
This project is distributed under the GNU General Purpose License. Please see LICENSE
for more information.