Host a Dashboard using Python, Dash, and Linux in your own Linux server

Hosting a Dash app on Ubuntu 20.04 using uWSGI and Nginx

Why Host a Dashboard?

Pre-installation

Get down to it

Dashboard App

Check your app works

python app.py

Install and prepare uWSGI

conda install -c conda-force uwsgi

Create wsgi.py

nano wsgi.py
from app import server as application
if __name__ == '__main__':
application.run()
uwsgi --socket 127.0.0.1:8050 --protocol=http -w wsgi

Create index.ini

nano index.ini
[uwsgi]
module = wsgi
master = true
processes = 4
socket = index.sock
chmod-socket = 660
vacuum = true
die-on-term = true

Create Index.service Systemd Unit File

nano /etc/systemd/system/index.service
[Unit]
Description=uWSGI instance to serve index
After=network.target
[Service]
User=carpiero
Group=www-data
WorkingDirectory=/home/carpiero/ir/DataTown
ExecStart=/home/carpiero/miniconda3/envs/server_env/bin/uwsgi --force-cwd /home/carpiero/ir/DataTown --ini index.ini
[Install]
WantedBy = multi-user.target
sudo systemctl restart index.service
sudo systemctl status index.service

Configure Nginx

sudo nano /etc/nginx/sites-available/datatown
server { server_name www.datatown.es;if ($host = www.datatown.es) { 
return 301 https://datatown.es$request_uri;
}
location / {
include uwsgi_params;
uwsgi_pass unix:/home/carpiero/ir/DataTown/index.sock;
}
}

That’s it

💻 Data Analyst | 📊 MBA | 🤖 Machine Learning | 📈 Controller