Last active
July 9, 2019 11:08
-
-
Save okomarov/d79acb1736abe48e17291cf300a4997e to your computer and use it in GitHub Desktop.
__init__ for multiple dash apps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def create_app(): | |
| server = Flask(__name__) | |
| server.config.from_object(BaseConfig) | |
| from app.dashapp1.layout import layout as layout1 | |
| from app.dashapp1.callbacks import register_callbacks as register_callbacks1 | |
| register_dashapp(server, 'Dashapp 1', 'dashboard', layout1, register_callbacks1) | |
| from app.dashapp2.layout import layout as layout2 | |
| from app.dashapp2.callbacks import register_callbacks as register_callbacks2 | |
| register_dashapp(server, 'Dashapp 2', 'example', layout2, register_callbacks2) | |
| register_extensions(server) | |
| register_blueprints(server) | |
| return server | |
| def register_dashapp(app, title, base_pathname, layout, register_callbacks_fun): | |
| # Meta tags for viewport responsiveness | |
| meta_viewport = {"name": "viewport", "content": "width=device-width, initial-scale=1, shrink-to-fit=no"} | |
| my_dashapp = dash.Dash(__name__, | |
| server=app, | |
| url_base_pathname=f'/{base_pathname}/', | |
| assets_folder=get_root_path(__name__) + f'/{base_pathname}/assets/', | |
| meta_tags=[meta_viewport]) | |
| # Push an application context so we can use Flask's 'current_app' | |
| with app.app_context(): | |
| my_dashapp.title = title | |
| my_dashapp.layout = layout | |
| register_callbacks_fun(my_dashapp) | |
| _protect_dashviews(my_dashapp) | |
| ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment