Mod_wsgi and dash - virtual host configuration

Hello. I have looked at similar posts and experimented a bit and I have found myself a bit stuck trying to configure dash with mod_wsgi. Mostly I am confused about how to set up my virtual hosts (.conf) file. This is my first attempt at web hosting and I am a student, so I’m still figuring things out from scratch. By the way, I added a space before every “.com” in this post because the Dash forum does not allow me to put any ‘links’ (even though they are not links) in a forum post.

The name of my site is retirotigre. com.
My app is called test.py, it is in /var/www/retirotigre. com/:

import dash
import dash_core_components as dcc
import dash_html_components as html
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’
}
}
)
])
server = app.server
if name == ‘main’:
app.run_server(debug=True)

I also have my wsgi file, myapp.wsgi. It is in /var/www/retirotigre.com/wsgi-scripts:

#!/usr/bin/env python
import sys
import logging
sys.stdout = sys.stderr
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,“/var/www/retirotigre. com/”)
from test import server as application

Then, in /etc/httpd/sites-available/retirotigre. com.conf, I have my virtual hosts setup as follows:

<VirtualHost *:80>
ServerName www.retirotigre. com
ServerAlias retirotigre. com
DocumentRoot /var/www/retirotigre. com/html
ErrorLog /var/www/retirotigre.com/log/error.log
CustomLog /var/www/retirotigre.com/log/requests.log combined

When I go to localhost/myapp, I see “Loading…” that never loads. The code compiles. In developer tools I get an error that says: ReferenceError: DashRenderer is not defined. I have searched online but this error seems rare, or at least there is not much info on it.

Thank you in advance for any suggestions you may have as to how I configure my dash application. I have tried all solutions from the other two threads on this with no luck.

-mr. berry

Welcome @mr.berry :slight_smile:
Looks like the url routing didn’t get properly passed along to the front end - if you look at the network tab in developer tools, do you see a failed request for <host>/_dash-component-suites/dash_renderer/dash_renderer.dev.js?...? That probably needs to get myapp inserted after <host>, which is what requests_pathname_prefix is for:

app = dash.Dash(requests_pathname_prefix='/myapp/')

See https://dash.plot.ly/integrating-dash

1 Like

Dear alexcjohnson,

I am so grateful for your response. That made the app work. Endless thanks. Hopefully this helps the next person who runs into this issue!

1 Like

Cool. Thanks @alexcjohnson .This solution works for me.

@alexcjohnson I’m facing the same issue. This is my definition.
index_app = dash.Dash(server=flask_app, name="Dashbar", meta_tags=[{'name':'viewport', 'content': 'width=device-width, initial-scale=0.8, maximum-scale=1.2, minimum-scale=0.8, shrink-to-fit=yes'}], title="Stock Simulation", update_title=None, external_stylesheets=[dbc.themes.BOOTSTRAP], url_base_pathname="/dash/"). It works fine in my local but gives error on server. This is the routing -
@server.route('/dash/') def render_dashboard(): return redirect('/dash/')
I guess the application is not able to find assets and static folder while on server thats why the error. This is the structure of my app.

Please help me if you have any solution. Thank you