def test_bluprint_component_with_no_prefix(): div = None # Create Dash/SPA blueprint test = Blueprint('test') @test.route('/ticker', title='Ticker', prefix_ids=False) def ticker(ctx): nonlocal div div = html.H2('Hello World', id='hello') test.callback(div.output.children, div.input.n_clicks) def _callback(clicks): return None # Create and layout Dash/SPA app create_spa(test) # Confirm the component prefix is {blueprint}.{route} assert div.id == 'hello'
import dash_html_components as html import dash_core_components as dcc from dash_spa import Blueprint spa = Blueprint('welcome') header_text = """ Dash/SPA is a minimal framework and component suite that allows you to build complex Dash based single-page applications with ease. The demo application includes several well known Dash examples that have been pasted into the SPA framework to show how easy it is to transition to SPA. The framework, component suite and demo are 100% Python """ def jumbotron_header(title, text): return html.Header([ html.H1(title, className='display-3'), html.P(text), ], className='jumbotron my-4') def card(title, text, link=None): return html.Div( [ html.Div( [ html.Img(alt=''), html.Div([
from dash_spa import Blueprint blueprint = Blueprint('user')
from collections import namedtuple from dash import html from dash_spa import Blueprint from dash_spa.admin.exceptions import InvalidAccess blueprint = Blueprint('admin') def form_values(dt): obj = namedtuple("FormFields", dt.keys())(*dt.values()) return obj def form_layout(title, form): return html.Div([ html.Div([ html.Div([ html.Div([ html.H4(title, className="card-title"), form, ], className='card-body') ], className="card fat") ], className="col-6 mx-auto") ], className="row align-items-center h-100") def validate_user(ctx): login_manager = ctx.login_manager if login_manager.isAdmin(): return True raise InvalidAccess("Must be signed in as admin")
from utils import logging, log import dash_html_components as html from dash_spa import spa, Blueprint from app import app as dash_app test = Blueprint('test') @test.route('/page1') def route1(): spa = test.get_spa('page1') btn = spa.Button('Page #2', id='btn') redirect = spa.Redirect(id='redirect') @spa.callback(redirect.output.href, [btn.input.n_clicks]) def _cb(clicks): red = test.NOUPDATE log.info('btn clicks=%s', clicks) if clicks: red = test.url_for('page2') return red return html.Div([html.H2('Page #1'), btn, redirect]) @test.route('/page2') def route2(): spa = test.get_spa('route2')
from dash_spa import Blueprint blueprint = Blueprint('demo')
from dash_spa import spa, Blueprint import dash_html_components as html from app import app as dash_app demo = Blueprint('demo') NAV_BAR_ITEMS = { 'brand': { 'title': 'SPA/Example', 'href': '/' }, 'left': [ { 'title': 'Page1', 'endpoint': 'demo.page1' }, { 'title': 'Page2', 'endpoint': 'demo.page2' }, ], } def big_center(text): return html.H2(text, className='display-3 text-center') @demo.route('/page1') def test1(): return html.Div([