Tuesday, April 28, 2020

Deploy Dash application on Apache

Following are example scripts to deploy Dash application in a sub-domain on an Apache web server installed with Flask and Dash modules. Hopefully this will be useful to someone who also experienced annoying issues of Dash stuck at a white window with “Loading…” or “dash error loading layout”.

Assume we will deploy the application in https://www.example.com/user1/myapp. First setup wsgi script, say "index.wsgi", in the application folder with the following content:

import sys
# add your app directory to the sys.path
project_home = u'/home/users/user1/www/myapp' #specify to the correct path
if project_home not in sys.path:
    sys.path = [project_home] + sys.path
# need to pass the flask app as "application" for WSGI to work
# for a dash app, that is at app.server
# see https://plot.ly/dash/deployment
from dashing_demo_app import app
application = app.server
app.config.update({
    # as the proxy server will remove the prefix
    #'routes_pathname_prefix': '',
    # the front-end will prefix this string to the requests
    # that are made to the proxy server
    'requests_pathname_prefix': '/user1/myapp/index.wsgi/'
})

Please note that you need to specify requests_pathname_prefix to your url path, as it is the key to resolve the above issues of loading Dash app.

An example app script "dashing_demo_app.py" can be found from the reference link at the end (also copied below)
import dash
import dash_core_components as dcc
import dash_html_components as html # for deployment, pass app.server (which is the actual flask app) to WSGI etc
app = dash.Dash() app.layout = html.Div(children=[
html.H1(children='Hello Dash'), html.Div(children='''
Dash: A web application framework for Python.
'''), dcc.Graph(
id='example-graph',
figure={
'data': [
{'x': [1, 2, 3], 'y': [4, 1, 2], 'type': 'bar', 'name': 'SF'},
{'x': [1, 2, 3], 'y': [2, 4, 5], 'type': 'bar', 'name': u'Montréal'},
],
'layout': {
'title': 'Dash Data Visualization'
}
}
)
])

The original wsgi script and demo script are from https://github.com/conradho/dashingdemo/

1 comment:

Anonymous said...

For occasion, an operator 'licensed' in Costa Rica could only have thecasinosource.com an web business license, whereas an operator licensed in Curacao is subject to the legal guidelines of the Netherlands. However, regulators there cease want of|wanting} managing disputes or implementing fair terms and situations. They enlist the help of web infrastructure operators in blocking these sites. Operators simply monitor the Server Name Identification subject to look at the paths of all traffic however not the content of any given site.