A tool for combining Dash apps on a single server
Project description
Dash Manager
Dash Manager is an easy-to-use device that allows you to combine multiple Dash applications on a single Flask server. A layout wrapper is also adding for each application into which common elements, such as the navigation bar, can be encoded.
Simple Example
from dash_manager import DashManager, BaseView
from dash import Dash, html
manager = DashManager(template_mode='bootstrap') # or mantine
# Pages
page = Dash(name='First Dashboard')
page.layout = lambda: html.Div('This is First Dashboard')
page2 = Dash(name='Second Dashboard', url_base_pathname='/two/')
page2.layout = lambda: html.Div('This is Second Dashboard')
page3 = Dash(name='Third Dashboard', url_base_pathname='/three/')
page3.layout = lambda: html.Div('This is Third Dashboard')
# Views
manager.add_view(BaseView(page, category='Dropdown'))
manager.add_view(BaseView(page2, category='Dropdown'))
manager.add_view(BaseView(page3))
# Run app
manager.run(debug=True)
Instalation
Dash-manager is published as a Python package and can be installed with pip, ideally by using a virtual environment. Open up a terminal and install dash-manager with:
pip install dash-manager
This will automatically install compatible versions of all dependencies: Flask, Dash, Dash Bootstrap & Dash Mantine. Dash manager always strives to support the latest versions, so there's no need to install those packages separately.
Creating your app
After you've installed Dash Manager, you can create a recommended application structure. Go to the directory where you want your project to be located and enter:
dash_manager new *
This will create the following structure, where in each file there will be detailed descriptions:
.
├─ assets/
├─ webApp/
│ └─ views
│ └─ first_dash
│ └─ __init__.py
│ └─ app.py
│ └─ second_dash
│ └─ __init__.py
│ └─ app.py
│ └─ __init__.py
│ └─ __init__.py
│ └─ config.py
│ └─ server.py
└─ wsgi.py
The resulting project is a basic application that can be run via wsgi.py:
python wsgi.py
Protecting
Dash Manager lets you define access control rules on each of your view classes by simply overriding the is_accessible method. How you implement the logic is up to you, but if you were to use a low-level library like Flask-Login, then restricting access could be as simple as:
from dash_manager import BaseView
from flask import redirect, url_for
from flask_login import current_user
class MyView(BaseView):
def is_accessible(self):
return current_user and current_user.is_authenticated
def inaccessible_callback(self, name, **kwargs):
# redirect to login page if user doesn't have access
return redirect(url_for('login', next=request.url))
In the navigation menu, components that are not accessible to a particular user will not be displayed for that user. The main drawback is that you still need to implement all of the relevant login, registration, and account management views yourself.
Customization
You can use three built-in themes for your application: Bootstrap, Mantine & Clear. But if you need a completely custom interface: override dash_manager.manager.template.BaseTemplate class.
class MyTemplate(BaseTemplate):
def navbar(self, menu: list, links: list):
"""
Override this method to create a custom navigation bar
Menu is list of dash_manager.manager.menu.MenuView or
dash_manager.manager.menu.MenuCategory object
"""
...
def app_container(self, navbar, app_layout, footer):
"""
Override this method to create a custom container
"""
...
def footer(self):
"""
Override this method to create a custom footer
"""
...
Read more about this here
Grouping Views
When adding a view, specify a value for the category parameter to group related views together in the menu:
manager.add_view(BaseView(page, category='Dropdown'))
manager.add_view(BaseView(page2, category='Dropdown'))
This will create a top-level menu item named ‘Dropdown’, and a drop-down containing links to the two views.
And to add arbitrary buttons to the menu:
btn = dmc.Anchor(
dmc.ActionIcon(
DashIconify(
icon='radix-icons:avatar', width=22
),
variant="outline",
radius='md',
size=36,
color='indigo',
),
href='/profile',
refresh=True)
manager.add_link(btn)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file dash_manager-1.0.1.tar.gz
.
File metadata
- Download URL: dash_manager-1.0.1.tar.gz
- Upload date:
- Size: 17.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a4dfec71782dbc77c41328a52b5be9337ab74a77fdc4fe6c187b8258d036717 |
|
MD5 | 82e469cbd72ab4846e1d67bcca1c0888 |
|
BLAKE2b-256 | 24e44133b0b7893a56d02ad10e30fbd289ed34d35683afe363a20a4507446d70 |