Skip to main content

Dash Single Page Application (SPA) Framework

Project description

dash-spa

Dash/SPA is a minimal template and component suite that allows you to build complex Dash based multi-page applications with ease. The demo application includes several well known Dash demos that have been pasted into the SPA framework to show how easy it is to transition to SPA.

Dash/SPA supports Flask style Blueprints and route decorators:

Code Snippet

pip install dash-spa
from dash import html
from dash_spa import Blueprint

greetings = Blueprint('greetings')

@greetings.route('/hello')
def hello():
    return html.H2('Dash/SPA says HELLO!')

@greetings.route('/goodby')
def goodby():
    return html.H2('Dash/SPA says GOODBY!')

...

app.register_blueprint(greetings, url_prefix='/test/greetings')

Dash/SPA manages component IDs using blueprint/route based namespaces. This greatly reduces Dash component ID conflicts. A component ID is only defined once when the component is created. It is then used by reference in associated Dash callbacks:

from dash import html
import dash_bootstrap_components as dbc
import dash_holoniq_components as dhc

user_name = dbc.Input(id='user', placeholder="Enter name")
password = dhc.PasswordInput("Password", name='password', id='password', placeholder="Enter password")

btn = html.Button('Enter', id='enter', disabled=True)

@app.callback(btn.output.disabled, [user_name.input.value, password.input.value])
def _cb_enter(user_name, password):
    return not db_validate_user(user_name, password)

Dash components created outside of a blueprint route are prefixed with the enclosing modules name (__NAME__)

Routes can be protected by an arbitrary access validation function:

@admin.route('/users', title='Admin Users', access=validate_user)
def user_view(ctx):
  pass

In the example, validate_user throws an exception if the user is not signed in. This results in a 404 page being displayed

Dash/SPA includes an optional NAVBAR, configured by a simple dictionary:

NAV_BAR_ITEMS = {
    'brand' : spa.NavbarBrand('Dash/SPA','/'),
    'left' : [
        spa.NavbarLink('Global Warming','/demo/warming'),
        spa.NavbarLink('State Solar', '/demo/solar'),
        spa.NavbarLink('Ticker', '/demo/ticker?tickers=COKE'),
        spa.NavbarLink('Profile', '/user/profile'),
        spa.NavbarLink('Admin', '/admin/users'),
    ],
    'right': [
        AdminNavbarComponent()
    ],

    'footer': spa.Footer('SPA/Examples'),
}

Dash/SPA Allows easy creation of interactive forms

frm = SpaForm(ctx,'loginFrm')

email = frm.Input('Email', name='email', type='email', placeholder="Enter email")
password = frm.PasswordInput("Password", name='password', placeholder="Enter password")
button = html.Button('Sign In', type='submit')

form = frm.Form([
    email,
    password,
    button,
], title='Sign In'),


@app.callback(form.output.children, [form.input.form_data])
def _form_submit(values):
    print(values)
    return spa.NOUPDATE

Admin Blueprint

Dash/SPA Includes an optional admin blueprint that supports user registration, email authentication and login. This is provided as a demonstrator, careful consideration to the security implications should be undertaken before using it in a public website.

Views are provided that allow:

  • Register, name, email, password. Verification code send by email.

  • Enter the email verification code.

  • Normal user login.

  • Reset forgotten password, Password reset code sent by email.

  • Enter password reset code.

  • Enter new password, confirm new password.

  • Login using new password.

  • User admin table with Add, Edit and Delete. Accessible only when signed in with admin rights.

Documentation

Head over to the README for more details.

Contributing

The source code for dash-spa is available on GitHub. If you find a bug or something is unclear, we encourage you to raise an issue. We also welcome contributions, to contribute, fork the repository and open a pull request.

Project details


Download files

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

Source Distribution

dash-spa-0.8.2.tar.gz (28.7 kB view details)

Uploaded Source

Built Distribution

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

dash_spa-0.8.2-py3-none-any.whl (32.6 kB view details)

Uploaded Python 3

File details

Details for the file dash-spa-0.8.2.tar.gz.

File metadata

  • Download URL: dash-spa-0.8.2.tar.gz
  • Upload date:
  • Size: 28.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.12

File hashes

Hashes for dash-spa-0.8.2.tar.gz
Algorithm Hash digest
SHA256 55778b8d04653164fe04eb5a60ab663c48ad5dc75946495803cf1b2b9c13289c
MD5 e6b3deb87b8026236aae819e39e22b0b
BLAKE2b-256 56a18cbdcf4f0bec1f561cb66217c1085c0c11f979e60c2004b0e95e7493752d

See more details on using hashes here.

File details

Details for the file dash_spa-0.8.2-py3-none-any.whl.

File metadata

  • Download URL: dash_spa-0.8.2-py3-none-any.whl
  • Upload date:
  • Size: 32.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.12

File hashes

Hashes for dash_spa-0.8.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b475e501407676b423dde1db46a22449dfec0411e5cd6ea19d05c89852529352
MD5 8fb3cc8895869a8fbe6ea3f7f8551c6c
BLAKE2b-256 a9349cf33aedb9a5706e1a45560b20f86cbc7ca35bea877ee77cb9be778362eb

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