Using flask and DispatcherMiddleware to run multiple dash apps

Hey all.

I’m having a problem, probably a misunderstanding of how flask/dash actually works.

I have this:

dash_app1 = Dash(__name__)
dash_app1.layout = html.Div('Test...')
dash_app2 = Dash(__name__)
dash_app1.layout = html.Div('Test Again...')
flask_app = Flask(__name__)


flask_app.wsgi_app = DispatcherMiddleware(NotFound(), {
    "/app1": dash_app1.server,
    '/app2': dash_app2.server,
})

if __name__ == "__main__":
    flask_app.run()

However, I get the error:

127.0.0.1 - - [25/Jun/2021 02:10:55] "GET /_dash-component-suites/dash_renderer/polyfill@7.v1_8_3m1610134889.8.7.min.js HTTP/1.1" 404 -

With the actual page displaying a “Loading…”

Would anyone know how to make this work?

Thanks!

You need to set requests_pathname_prefix when creating the dash apps so they try to load the JavaScript bundles from the correct place. Check out this post for more details and a simple example.