🚀 Gen 5 of the leading AI app deployment platform launches October 6. Click for the livestream.

Host dash under alternate path

Say I have a website http://example_dot_com and I want to use Dash to show some nice graphs. I want to host these graphs under http://example_dot_com/cool_data. I don’t want to re-build my entire website using dash. I was thinking that I could use nginx to specify a proxy such that /cool_data goes to host_running_dash:8050. I have gotten that part working using this slightly adapted example from the gunicorn website:

  server {
    listen 80;
    server_name example_dot_com;

    location /cool_data {
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

The problem now is that the client is making requests for things like /_dash-dependencies and /_dash-layout rather than /cool_data/_dash-dependencies. I’m assuming that these requests are based on the content that is being returned when http://example_dot_com/cool_data is visited. Is there any way to inform Dash that it’s being hosted under a different URL? Or is my strategy here totally wrong?

Hey, welcome to the forums!

Yep, there’s a Dash class initialisation parameter for changing the request URL prefixes, for just this situation.

Dash has both requests_pathname_prefix and routes_pathname_prefix. By adding the prefix in nginx, you have effectively set routes_pathname_prefix to be /cool_data. So now you need to changed requests_pathname_prefix to match this.

1 Like

Thanks for your response @nedned. I ended up with this:

pathname_params = dict()
if my_settings.hosting_path is not None:
    pathname_params["routes_pathname_prefix"] = "/"                                                                                                                                                                                                                              
    pathname_params["requests_pathname_prefix"] = "/{}/".format(my_settings.hosting_path)                                                                                                                                                                                   
app = dash.Dash(__name__, external_stylesheets=external_stylesheets, server=server, **pathname_params)


You can also omit setting routes_pathname_prefix, you just need to set requests_pathname_prefix