Skip to content

Setup front end with plotly dash, flask, gunicorn and nginx

Pan Deng edited this page May 23, 2018 · 2 revisions

1. Setup flask framework

Refer to instructions at: https://github.com/InsightDataScience/data-engineering-ecosystem/wiki/Flask

2. Build dash application on top of flask

dash and components can be downloaded via pip.

To connect dash to flask:

# Define for IIS module registration.
wsgi_app = app.wsgi_app

# Connect dash to flask
dashapp = dash.Dash(__name__, server=app, url_base_pathname='/')

3. Get a domain

Buy a domain at namecheap.com

4. Point domain name to EC2 instances

Follow the instructions here: http://techgenix.com/namecheap-aws-ec2-linux/ Create host zones and add the servers to domain's custom DNS

5. Nginx and gunicorn

sudo apt-get install nginx
conda install gunicorn
sudo /etc/init.d/nginx
sudo rm /etc/nginx/sites-enabled/default
sudo touch /etc/nginx/sites-available/application
sudo ln -s /etc/nginx/sites-available/application /etc/nginx/sites-enabled/application
sudo nano /etc/nginx/sites-enabled/application

And paste (exactly):

server {
    location / {
        proxy_pass http://localhost:8000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}

Finally, run gunicorn foldername:appvariablename outside the folder. (Appvariablename: Flask(__name__))

In this case: GeneMiner/flask-dash-app $ gunicorn app:app

To run in the background: GeneMiner/flask-dash-app $ gunicorn app:app -D

Kill the process: pkill gunicorn