Skip to main content

A simple router for multi page Dash applications.

Project description

dash_router

A simple router for multi page Dash applications. Uses Werkzeug rules.

Install

 $ pip install dash-router

Usage

Use the built-in helper method:

import dash
import dash_core_components as dcc
import dash_html_components as html
from dash_router import Router


external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']


app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
router = Router()
router.register_callbacks(app)


@router.route('/')
def page1():
    return html.Div([
        dcc.Link('Navigate to "/"', href='/'),
        html.Br(),
        dcc.Link('Navigate to "/page-2"', href='/page-2'),

        html.H1(children='Hello from Page 1')
    ])


@router.route('/page-2')
def page2():
    return html.Div([
        dcc.Link('Navigate to "/"', href='/'),
        html.Br(),
        dcc.Link('Navigate to "/page-2"', href='/page-2'),

        html.H1(children='Hello from Page 2')
    ])



if __name__ == '__main__':
    app.run_server(debug=True)

or manually add it to an existing app:

import dash
import dash_core_components as dcc
import dash_html_components as html
from dash_router import Router


external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']


app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
router = Router()


@router.route('/')
def page1():
    return html.H1(children='Hello from Page 1')


@router.route('/page-2')
def page2():
    return html.H1(children='Hello from Page 2')



app.layout = html.Div([
    dcc.Location(id='url', refresh=False),
    dcc.Link('Navigate to "/"', href='/'),
    html.Br(),
    dcc.Link('Navigate to "/page-2"', href='/page-2'),

    html.Div(id='page-content'),
])


@app.callback(
    dash.dependencies.Output('page-content', 'children'),
    [dash.dependencies.Input('url', 'pathname')]
)
def display_page(pathname):
    return router.dispatch(pathname)


if __name__ == '__main__':
    app.run_server(debug=True)    

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dash_router-0.2.0-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file dash_router-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: dash_router-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.7

File hashes

Hashes for dash_router-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2a58c48f132548686cb4fd6b478ba7cef06a4a7f644a833406437259f7a74ef6
MD5 064e99dee8101300e20f2f941d21f59a
BLAKE2b-256 fa900ad223b6354713c9117d769b0161962f8f75b660341247194b7e8823331a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page