A plugin to simplify creating multi-page Dash apps

Overview

Multi-Page Dash App Plugin

A plugin to simplify creating multi-page Dash apps. This is a preview of functionality that will of Dash 2.1.

Background

The goal of this plugin is to remove as much boilerplate as possible when creating multi-page Dash apps.

This plugin allows users to simply place their layouts in pages/ and call dash.register_page with the desired URL path of that page.

This plugin will automatically:

  • Create the URL routing callback
  • Add page information to dash.page_registry that can be used when creating navigation bars
  • Set validate_layout accordingly so that you don't need to suppress_callback_exceptions for simple multi-page layouts
  • Set the order of dash.page_registry based off order and the filename
  • Set </code> and and their social media equivalents accordingly in the index_string of the HTML that is served on page-load
  • Set a clientside callback to update the </code> as you navigate pages with dcc.Link
  • Set the social media meta image accordingly based off of images available in assets

Usage

Option 1 - In this project

Clone this repo and then run python app.py. pages_plugin.py is the functionality that will become part of the dash library. The pages/ folder demonstrates examples of how to use dash.register_page.

Option 2 - In your own projects

  1. Copy pages_plugin.py into your project folder. In the future, this will be part of dash and you won't need to copy this file.
  2. In app.py, pass the plugin into Dash:
import pages_plugin

app = Dash(__name__, plugins=[pages_plugin])
  1. Create a folder called pages/ and place your app layouts in files within that folder. Each file needs to:
  • Define layout. This can be a variable or function that returns a component
  • Call dash.register_page(__name__) to tell pages_plugin that this page should be part of the multi-page framework

For example: pages/historical_outlook.py

import dash
from dash import html

dash.register_page(__name__)

def layout():
    return html.Div('This page is the historical outlook')

dash.register_page will can accept various arguments to customize aspects about the page like path (the URL of the page), title (the browser tab's title of the page), and more. See the API reference below for details.

pages/home.py

import dash
from dash import html

dash.register_page(
    __name__,
    path='/',
    title='Analytics App'
)

def layout():
    return html.Div('This is the home page')
  1. Modify app.layout to display the URLs for page navigation and include the container that displays the page's content.
  • dash.page_registry: The page URLs can be found in dash.page_registry. This is an OrderedDict with keys being the page's module name (e.g. pages.historical_outlook) and values being a dictionary containing keys path, name, order, title, description, image, and layout. This page_registry is populated from calling dash.register_page within pages/.
  • pages_plugin.page_container: This component defines where the page's content will render on page navigation.

app.py

import pages_plugin

app = Dash(__name__, plugins=[pages_plugin])

app.layout = html.Div([
    # Display the URLs by looping through `dash.page_registry`
    # In practice, this might be a `ddk.Header` or a `dbc.NavbarSimple`
    html.Div([dcc.Link(page['name'], href=page['path']) for page in dash.page_registry),
    
    html.Hr()
    
    # Set the container where the page content will be rendered into on page navigation
    pages_plugin.page_container
])

Refrence

dash.register_page

def register_page(
    module,
    path=None,
    name=None,
    order=None,
    title=None,
    description=None,
    image=None,
    layout=None,
    **kwargs
):

Assigns the variables to dash.page_registry as an OrderedDict (ordered by order).

dash.page_registry is used by pages_plugin to set up the layouts as a multi-page Dash app. This includes the URL routing callbacks (using dcc.Location) and the HTML templates to include title, meta description, and the meta description image.

dash.page_registry can also be used by Dash developers to create the page navigation links or by template authors.

  • module: The module path where this page's layout is defined. Often __name__.

  • path: URL Path, e.g. / or /home-page. If not supplied, will be inferred from module, e.g. pages.weekly_analytics to /weekly-analytics

  • name: The name of the link. If not supplied, will be inferred from module, e.g. pages.weekly_analytics to Weekly analytics

  • order: The order of the pages in page_registry. If not supplied, then the filename is used and the page with path / has order 0

  • title: The name of the page . That is, what appears in the browser title. If not supplied, will use the supplied name or will be inferred by module, e.g. pages.weekly_analytics to Weekly analytics

  • description: The . If not supplied, then nothing is supplied.

  • image: The meta description image used by social media platforms. If not supplied, then it looks for the following images in assets/:

    • A page specific image: assets/. is used, e.g. assets/weekly_analytics.png
    • A generic app image at assets/app.
    • A logo at assets/logo.
  • layout: The layout function or component for this page. If not supplied, then looks for layout from within the supplied module.

  • **kwargs: Arbitrary keyword arguments that can be stored

page_registry stores the original property that was passed in under supplied_ and the coerced property under . For example, if this was called:

register_page(
    'pages.historical_outlook',
    name='Our historical view',
    custom_key='custom value'
)

Then this will appear in page_registry:

OrderedDict([
    (
        'pages.historical_outlook', 
        dict(
            module='pages.historical_outlook',
            
            supplied_path=None,
            path='/historical-outlook',
            
            supplied_name='Our historical view',
            name='Our historical view',
            
            supplied_title=None,
            title='Our historical view'
            
            supplied_description=None,
            description='Our historical view',
            
            supplied_order=None,
            order=1,
            
            supplied_layout=None,
            layout=<function pages.historical_outlook.layout>,
            
            custom_key='custom value'
        )
    ),
])
You might also like...
A script to generate the m3u playlist containing direct streamable file (.mpd or MPEG-DASH or DASH) based on the channels that the user has subscribed on the Tata Sky portal. You just have to login using your password or otp that's it . Plotly Dash Command Line Tools - Easily create and deploy Plotly Dash projects from templates
Plotly Dash Command Line Tools - Easily create and deploy Plotly Dash projects from templates

🛠️ dash-tools - Create and Deploy Plotly Dash Apps from Command Line | | | | | Create a templated multi-page Plotly Dash app with CLI in less than 7

A python script to simplify recompiling, signing and installing reverse engineered android apps.

urszi.py A python script to simplify the Uninstall Recompile Sign Zipalign Install cycle when reverse engineering Android applications. It checks if d

Page to PAGE Layout Analysis Tool

P2PaLA Page to PAGE Layout Analysis (P2PaLA) is a toolkit for Document Layout Analysis based on Neural Networks. 💥 Try our new DEMO for online baseli

PAGE XML format collection for document image page content and more
PAGE XML format collection for document image page content and more

PAGE-XML PAGE XML format collection for document image page content and more For an introduction, please see the following publication: http://www.pri

split-manga-pages: a command line utility written in Python that converts your double-page layout manga to single-page layout.

split-manga-pages split-manga-pages is a command line utility written in Python that converts your double-page layout manga (or any images in double p

Plotly Dash plugin to allow authentication through 3rd party OAuth providers.

dash-auth-external Integrate your dashboards with 3rd parties and external OAuth providers. Overview Do you want to build a Plotly Dash app which pull

This app makes it extremely easy to build Django powered SPA's (Single Page App) or Mobile apps exposing all registration and authentication related functionality as CBV's (Class Base View) and REST (JSON)

Welcome to django-rest-auth Repository is unmaintained at the moment (on pause). More info can be found on this issue page: https://github.com/Tivix/d

Width-customizer-for-streamlit-apps - Width customizer for Streamlit Apps
Width-customizer-for-streamlit-apps - Width customizer for Streamlit Apps

🎈 Width customizer for Streamlit Apps As of now, you can only change your Strea

minipdf is a package for creating simple, single-page PDF documents.
minipdf is a package for creating simple, single-page PDF documents.

minipdf minipdf is a package for creating simple, single-page PDF documents. Installation You can install the development version from GitHub with: #

Creating delicious APIs for Django apps since 2010.

django-tastypie Creating delicious APIs for Django apps since 2010. Currently in beta but being used actively in production on several sites. Requirem

An MkDocs plugin that simplifies configuring page titles and their order

MkDocs Awesome Pages Plugin An MkDocs plugin that simplifies configuring page titles and their order The awesome-pages plugin allows you to customize

Setup a flask project using a single command, right from creating virtual environment to creating Procfile for deployment.

AutoFlask-Setup About AutoFlask-Setup can help you set up a new Flask Project, right from creating virtual environment to creating Procfile for deploy

Hydralit package is a wrapping and template project to combine multiple independant Streamlit applications into a multi-page application.
Hydralit package is a wrapping and template project to combine multiple independant Streamlit applications into a multi-page application.

Hydralit The Hydralit package is a wrapping and template project to combine multiple independant (or somewhat dependant) Streamlit applications into a

A library to create multi-page Streamlit applications with ease.
A library to create multi-page Streamlit applications with ease.

A library to create multi-page Streamlit applications with ease.

Using Streamlit to host a multi-page tool with model specs and classification metrics, while also accepting user input values for prediction.

Predicitng_viability Using Streamlit to host a multi-page tool with model specs and classification metrics, while also accepting user input values for

BuddyPress is an open source WordPress plugin to build a community site. In releases of BuddyPress from 5.0.0 before 7.2.1 it's possible for a non-privileged, regular user to obtain administrator rights by exploiting an issue in the REST API members endpoint. The vulnerability has been fixed in BuddyPress 7.2.1. Existing installations of the plugin should be updated to this version to mitigate the issue.
Automatically mock your HTTP interactions to simplify and speed up testing

VCR.py 📼 This is a Python version of Ruby's VCR library. Source code https://github.com/kevin1024/vcrpy Documentation https://vcrpy.readthedocs.io/ R

Automatically mock your HTTP interactions to simplify and speed up testing

VCR.py 📼 This is a Python version of Ruby's VCR library. Source code https://github.com/kevin1024/vcrpy Documentation https://vcrpy.readthedocs.io/ R

Owner
Plotly
Plotly
Shut is an opinionated tool to simplify publishing pure Python packages.

Welcome to Shut Shut is an opinionated tool to simplify publishing pure Python packages. What can Shut do for you? Generate setup files (setup.py, MAN

Niklas Rosenstein 6 Nov 18, 2022
A thing to simplify listening for PG notifications with asyncpg

asyncpg-listen This library simplifies usage of listen/notify with asyncpg: Handles loss of a connection Simplifies notifications processing from mult

ANNA 18 Dec 23, 2022
tade is a discussion/forum/link aggregator application. It provides three interfaces: a regular web page, a mailing list bridge and an NNTP server

tade is a discussion/forum/link aggregator application. It provides three interfaces: a regular web page, a mailing list bridge and an NNTP server

Manos Pitsidianakis 23 Nov 4, 2022
Link-tree - Script that iterate over the links found in each page

link-tree Script that iterate over the links found in each page, recursively fin

Rodrigo Stramantinoli 2 Jan 5, 2022
Install, run, and update apps without root and only in your home directory

Qube Apps Install, run, and update apps in the private storage of a Qube Building instrutions

Micah Lee 26 Dec 27, 2022
Install, run, and update apps without root and only in your home directory

Qube Apps Install, run, and update apps in the private storage of a Qube. Build and install in Qubes Get the code: git clone https://github.com/micahf

Micah Lee 26 Dec 27, 2022
Creating low-level foundations and abstractions for asynchronous programming in Python.

DIY Async I/O Creating low-level foundations and abstractions for asynchronous programming in Python (i.e., implementing concurrency without using thr

Doc Jones 4 Dec 11, 2021
Simple tool for creating changelogs

Description Simple utility for quickly generating changelogs, assuming your commits are ordered as they should be. This tool will simply log all lates

null 2 Jan 5, 2022
Napari plugin for loading Bitplane Imaris files .ims

napari-imaris-loader Napari plugin for loading Bitplane Imaris files '.ims'. Notes: For this plugin to work "File/Preferences/Experimental/Render Imag

Alan Watson 4 Dec 1, 2022
Techie Sneh 17 Nov 23, 2021