Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to organise a plotly dash project?

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?

like image 553
volodymyr Avatar asked Jun 25 '17 08:06

volodymyr


1 Answers

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
like image 172
volodymyr Avatar answered Nov 20 '22 01:11

volodymyr