Dash deploy on apache using mod_wsgi


#1

issue

Issue while hosting the dash on apache using mod_wsgi

wsgi file

import sys
sys.path.insert(0, “D:/Dashboard_Workspace/code_base/app_server”)

from myapp import server as app
application = app

Anyone faced such issue with apache hosting ?


#2

I’ve used mod_wsgi for running dash apps before just fine without seeing this error. Have you tried running your same app with the default builtin server?


#3

Yes I have tried the same app on default server, working fine (on the localhost)
eg : python myapp.py

After hosted on the apache 2.4 using mod_wsgi, throwing such weird error.

myapp.wsgi

import sys
sys.path.insert(0, “D:/Dashboard_Workspace/code_base/app_server”)
from myapp import server as app
application = app

myapp.py

import dash
app = dash.Dash(“dashboard”)
server = app.server

app.layout = html.Div([
create_header(),
create_links(),
html.Div(id=‘page-content’),

])

@app.callback(Output(‘page-content’, ‘children’),
[Input(‘url’, ‘pathname’)])
def display_page(pathname):
if pathname == ‘/svn’:
return svn_analytics.layout
elif pathname ==’/build’:
return build_analytics.layout
elif pathname == ‘/readme’:
return create_readme()
elif pathname == ‘/clear-cache’:
cache.clear()
if name == ‘main’:
app.run_server(debug=True, host=‘0.0.0.0’, port=8082, threaded=True)


#4

I can run your code without that issue using mod_wsgi-express. I am however running it on a linux environment, so there could be some relevant difference there.

One suggestion is to try using app = dash.Dash(__name__). Getting the name parameter correct is important for locating static files correctly, however I think that’s only relevant for adding custom static files in addition to the internal Dash ones, so it’s potentially a long shot, but worth a try.


#5

Thanks Ned,

I am running it on windows 10 OS using mod_wsgi 4.5.24 & python 3.6
will try with the mod_wsgi-express, thanks for updates

getting excpetion in the js files, not sure from where it gets loaded
I didn’t noticed any such path in python site-packages
http://localhost:8082/_dash-component-suites/dash_renderer/react-dom@15.4.2.min.js?v=0.11.3


#6

That is one of the JavaScript libraries Dash uses for the interface. It looks like you’re set these to use local copies (ie you’ve set app.scripts.config.serve_locally = True. Do you get the same behaviour when you remove that and scripts are then sourced from the CDN?

It could also be worth checking that you’re using all the latest version of the various Dash Python packages. (dash, dash-core-components, dash-html-components, dash-renderer)

@chriddyp Do you have any suggestions as to what might be going on?


#7

These are all good suggestions. I’d also recommend checking the network panel to see if the requests are getting made correctly.


#8

@nedned

I have set it to False,
app.config.suppress_callback_exceptions = False
app.css.config.serve_locally = False
app.scripts.config.serve_locally = False

All dash libraries (dash, dash-core-components, dash-html-components, dash-renderer) are upgraded.


#9

And the problem persists?

If so, could you post a screenshot of the network panel of the developer tools that shows a request for that JavaScript file?


#10

Requests for javascript files


#11

Here is the issue when click on the tab component, (loading html.div)


#12


#13

Hi,

I’m not sure of what I say, but could it be related to apache? What is your apache conf for this site ?


#14

Hi,

I am using apache 2.4 with mod_wsgi
LoadModule wsgi_module “mod_wsgi.cp36-win32.pyd”

I tried it on both windows 10 & ubuntu 16.04, same issue


#15

And what is in your /etc/apache2/sites-available/.conf (in linux, for window I don’t know where it is)?


#16

It’s wsgi file in which used the WsgiScriptAlias pointed to the wsgi.py file


#17

I’m afraid I’m out of suggestions also


#18

Hi.

I do not know neither.

Maybe this can help, here is my configuration to run dash under mod_wsgi:

apache conf in /etc/apache2/sites-available/test.conf

<VirtualHost *:80>
    ServerName localhost.dash
    WSGIDaemonProcess dash_app user=www-data group=www-data threads=5 python-home=/var/www/apli_dash/venv 
    WSGIProcessGroup dash_app
    WSGIScriptAlias / /var/www/test/wsgi.py
</VirtualHost>

python-home is for virtualenv setting.

And the wsgi.py file:

import sys
sys.path.insert(0, "/var/www/test")

from test import app

server = app.server
application = server

where test is the filename of the app.

With this skeleton, it works fine for me.

Python 3.5.3
libapache2-mod-wsgi-py3 : 4.5.11-1


#19

My dashboard.wsgi file for the apache2.4 on windows env

import sys

#Expand Python classes path with your app’s path
sys.path.insert(0, “D:/Dashboard_Workspace/code_base/app_server”)

from index import server as app

#Put logging code (and imports) here …

#Initialize WSGI app object
application = app

httpd.conf

<Directory D:/Dashboard_Workspace/My-DB-Latest-app/dashboard_code/app_server>
#Order allow,deny
#Allow from all
Require all granted

WSGIScriptAlias / D:/Dashboard_Workspace/My-DB-Latest-app/dashboard_code/app_server/dashboard.wsgi