12
votes

I am trying to figure out how to organise a dash project with multiple apps. All examples are single page apps and I want to have multiple dashes organised as one project to run by gunicorn (inside a docker container):

dash-project/
  app1/
     layout.py
     data.py
  app2/
     layout.py
     data.py
  run.py( or run.sh)

Is this a right way to go? What should be inside run.py or run.sh, if anything? How do I use gunicorn to serve multiple apps?

1
I would assume it would be laid out similarly to a flask app but I am not sure - rgalbo
this is the first question ever on stack overflow on plotly-dash, or at least the first one with that tag. pretty cool. - Max Power
I am sure there will be more soon. This is a super promising project. - volodymyr

1 Answers

12
votes

With latest (master) version of dash, you can build a multi-app project!

Structure

dash-project/
  app1/
     app.py
     datamodel.py
  app2/
     app.py
     datamodel.py
  mycomponents/
     ...
  server.py
  run.py

app1/app.py:

import dash
import app1.datamodel
..
from server import server

app = dash.Dash(name='app1', sharing=True, 
                server=server, url_base_pathname='/app1')

server.py

from flask import Flask
server = Flask(__name__)

run.py

from server import server as application

import app1.app
import app2.app    

Serve using uwsgi (can be easily exended to be used with nginx)

uwsgi --http 0.0.0.0:5000 --processes 4 --wsgi-file run.py