Skip to content

Instantly share code, notes, and snippets.

@TJM
Last active October 23, 2018 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TJM/04ed9bfbec98082eb97fb19242460299 to your computer and use it in GitHub Desktop.
Save TJM/04ed9bfbec98082eb97fb19242460299 to your computer and use it in GitHub Desktop.
WSGI file for a Dash / Plotly app with no hard coded paths. Picks up the "prefix" for DASH through the WSGI environment variable SCRIPT_NAME and uses the virtualenv "venv"
import os
import sys
my_directory=os.path.dirname(__file__)
if my_directory not in sys.path:
sys.path.insert(0,my_directory)
# Virtual Environment (./venv)
activate_this = os.path.join(my_directory, 'venv', 'bin', 'activate_this.py')
execfile(activate_this, dict(__file__=activate_this))
from index import app, server
# MyDashApp - Calls "server" after setting prefix
# SCRIPT_NAME is WSGIScriptAlias
class MyDashApp:
def __init__(self, application):
self.__application = application
def __call__(self, environ, start_response):
if environ.has_key('SCRIPT_NAME'):
prefix = str(environ['SCRIPT_NAME'])
if not prefix.endswith('/'):
prefix = prefix + '/'
app.config.requests_pathname_prefix = prefix
app.config.routes_pathname_prefix = prefix
return self.__application(environ, start_response)
application = MyDashApp(server)
<VirtualHost *>
ServerName localhost.localdomain
WSGIDaemonProcess dashboard user=dashboard group=dashboard threads=5
WSGIScriptAlias /dashboard /apps/dashboard/dashboard.wsgi
<Directory /apps/dashboard>
WSGIProcessGroup dashboard
WSGIApplicationGroup %{GLOBAL}
Require all granted
</Directory>
</VirtualHost>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment