Skip to main content

A tool and framework to simplify construction of Python Dash applications.

Project description

dash-builder

[!IMPORTANT] dash-builder and its developer(s) are not associated with the original dash project or its commercial parent, Plotly.

A tool and framework to simplify construction of Python Dash applications.

API Design

  • Create a project in the current working directory
> dash init
  • Create project called testproject in specified directory
> dash init testproject --location ~/projects
  • Add new page to current dash project in pages/ directory
> dash page NewPage
  • Add new page to current dash project in specific directory within pages/
> dash page NewPage --location archive

Installation

pip install dash-builder

Usage

dash-builder provides a simple command-line interface (CLI) for initiating and managing your dash project.

Initiating a Dash Project

The create command creates a new skeleton project. It takes a single argument, the name for the new project. You can use the --location option to choose the directory in which to create it. If no location is passed, it will be created in the current working directory.

 dashb create test-project
3/3 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Complete
test-project successfully created in /Users/<username>.
📂 test-project
├── 📂 pages
│   ├── home.py
│   └── not_found_404.py
└── app.py

dash-builder implements defines 2x classes to be used when building apps:

  • DashPage - all page modules should define a page object that inherits from this abstract base class.
  • DashView - all page components should be constructed as views that inerhit from this abstract base class.

Framework

Under this framework:

  • Applications are composed of pages using Dash's multi-page settings.
  • Page modules define a page-object that subclasses the DashPage.
  • Page layouts are collections of views, created by subclassing the DashView.
  • Views define individual or collections of dash components, or other views.
  • Views can be reused to create similar components.
  • IDs are managed via the Views to simplify callback management.
  • When re-using Views, pattern-matching callbacks can be useful to reduce the number of callbacks.

For example, the below:

  • my-dash-project/
    • pages/
      • home.py
    • views/
      • __init__.py
      • demo_input.py
      • demo_output.py
      • demo_view.py
      • demo_view_2.py
    • app.py
# app.py
import dash

from dash import html


app = dash.Dash(__name__, use_pages=True)

app.layout = html.Div(
    [
        html.H1("Demo Application"),
        html.Div(dash.page_container)
    ]
)

if __name__ == "__main__":
    app.run(debug=True)
# pages/home.py
import dash

from dash import html, Input, Output
from dash_builder import DashPage

from views import DemoView, DemoView2, DemoInput, DemoOutput


dash.register_page(__name__, path="/")

class HomePage(DashPage):
    @classmethod
    def valid_layout(cls, **kwargs):
        one = DemoView.create("one")
        two = DemoView.create("two")
        three = DemoView2.create("three")
        return html.Div([one, two, three])

def layout(**kwargs):
    return HomePage.layout(**kwargs)

@dash.callback(
    Output(DemoOutput.matched_id(), "children"),
    Input(DemoInput.matched_id(), "value")
)
def update_value(value: str) -> str:
    return value

@dash.callback(
    Output(DemoView2.id("three", "output"), "children"),
    Input(DemoView2.id("three", "input"), "value")
)
def update_value_2(value: str) -> str:
    return value
# views/demo_input.py
from dash import dcc
from dash_builder import DashView


class DemoInput(DashView):
    @classmethod
    def create(cls, id:str, **kwargs) -> dcc.Inupt:
        return dcc.Input(id=cls.id(id))
# views/demo_output.py
from dash import html
from dash_builder import DashView


class DemoOutput(DashView):
    @classmethod
    def create(cls, id: str, **kwargs) -> html.Pre:
        return html.Pre(id=cls.id(id))
# views/demo_view.py
from dash import html
from dash_builder import DashView

from . import DemoInput, DemoOutput


class DemoView(DashView):
    @classmethod
    def create(cls, id: str, **kwargs) -> html.Span:
        input = DemoInput.create(id)
        output = DemoOutput.create(id)
        return html.Span([input, output], id=cls.id(id))
# views/demo_view_2.py
from dash import html, dcc
from dash_builder import DashView


class DemoView2(DashView):
    @classmethod
    def create(cls, id: str, **kwargs) -> html.Span:
        input = dcc.Input(id=cls.id(id, "input"))
        output = html.Pre(id=cls.id(id, "output"))
        return html.Span([input, output], id=cls.id(id))

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_builder-0.2.0.tar.gz (20.3 kB view details)

Uploaded Source

Built Distribution

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

dash_builder-0.2.0-py3-none-any.whl (21.7 kB view details)

Uploaded Python 3

File details

Details for the file dash_builder-0.2.0.tar.gz.

File metadata

  • Download URL: dash_builder-0.2.0.tar.gz
  • Upload date:
  • Size: 20.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dash_builder-0.2.0.tar.gz
Algorithm Hash digest
SHA256 b7b6d95e20a8fb79f50f221ab503cf1bdcd6467ab176429efa97678d865d1b2c
MD5 1c80e6c5b130bc70aa6282f70d1ef10b
BLAKE2b-256 557151daa56707b82ee09edbc243b8c88859beda47993c274f98978749ed3096

See more details on using hashes here.

Provenance

The following attestation bundles were made for dash_builder-0.2.0.tar.gz:

Publisher: publish-package.yaml on robfs/dash-builder

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: dash_builder-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 21.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dash_builder-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 56880ac0a2bf2fc097fbae2442eb8636bd8197e47b94959b6ef3f0eaf3f0ac3a
MD5 0b8cd4f0ec4db2382592e99b43e51820
BLAKE2b-256 d08888001ed4e9ea13b38fb51c69f2ec1ad195543301b571fa33f0b4b19f287b

See more details on using hashes here.

Provenance

The following attestation bundles were made for dash_builder-0.2.0-py3-none-any.whl:

Publisher: publish-package.yaml on robfs/dash-builder

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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