dash-prefix
Plotly/Dash utility library that allows component IDs to use prefixed 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:
pip install dash-prefix
prefix() Returns a lambda that will prefix all component IDs with the given prefix. If no prefix is given one will be assigned.
from dash import html, callback
from dash_prefix import prefix
pfx = prefix()
user_name = dbc.Input(id=pfx('user'), placeholder="Enter name")
password = dhc.PasswordInput("Password", name='password', id=pfx('password'), placeholder="Enter password")
btn = html.Button('Enter', id=pfx('enter'), disabled=True)
@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)
isTriggered() Returns true if the given dash component was the reason for the enclosing callback being triggered
app = dash.Dash(__name__)
btn1 = html.Button("Button 1", id='btn1')
btn2 = html.Button("Button 2", id='btn3')
title = html.H1('Title', id='title')
@app.callback(title.output.children, btn1.input.n_clicks, btn2.input.n_clicks)
def _update(btn1_clicks, btn2_clicks):
if isTriggered(btn1.input.n_clicks):
return "Button1 Clicked"
if isTriggered(btn2.input.n_clicks):
return "Button2 Clicked"
return NOUPDATE
match() and trigger_index() Are Pattern-Matching Callback helpers
Match = match({'type': 'buttons', 'idx': ALL})
btn1 = html.Button('Button 1', id=Match.idx(1))
btn2 = html.Button('Button 2', id=Match.idx(2))
btn2 = html.Button('Button 3', id=Match.idx(3))
title = html.Div(id='title')
@callback(title.output.children, Match.input.n_clicks)
def _update_(button_clicks):
idx = trigger_index()
if idx is not None:
return f"Button {idx} triggered {button_clicks[idx]} times!"
return NOUPDATE
css_id All dash components are injected with a css_id property. This makes testing
with Dash Duo far less taxing.
title = html.Div('Title', id='title')
_title = dash_duo.find_element(title.css_id)
Can also be used with dictionary IDs
Match = match({'type': 'buttons', 'idx': ALL})
btn1 = html.Button('Button 1', id=Match.idx(1))
btn2 = html.Button('Button 2', id=Match.idx(2))
btn3 = html.Button('Button 3', id=Match.idx(3))
_btn3 = dash_duo.find_element(btn3.css_id)
Build the project
The dash-prefix package is available on pypi. If needed, to create a local tarball, first change the release version in dash_spa/_version.py, then:
rm -rf dist dash_spa.egg-info build
python setup.py sdist bdist_wheel
The tarball is in dist/dash_spa-.tar.gz
To install the tarball in a dash project:
pip install dash_spa-<version>.tar.gz
Testing
Pytest and Dash Duo are used for testing. To run these tests both the Chrome browser and Chrome driver must be installed.
To run the tests:
pytest
Publish
twine upload dist/*
Metadata
Release files for dash-prefix 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dash-prefix-0.0.4.tar.gz | 7.3 kB | Without provenance | Details for dash-prefix-0.0.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dash_prefix-0.0.4-py3-none-any.whl | Python 3 | none | any | Details for dash_prefix-0.0.4-py3-none-any.whl |
Total release size: 14.7 kB
Release files / dash-prefix-0.0.4.tar.gz
| Download URL | dash-prefix-0.0.4.tar.gz |
|---|---|
| Size | 7.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
65ffacf8a12a2a0b32acc7982474d0c808e4e5b24c852575b02c26b825659bb6
|
|
BLAKE2b-256 checksum How to use checksums |
baaf78b697bd84462a3ed52a4f4a19085f916c3db01a714ab9730d39539d036f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.11.4 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.64.0 CPython/3.8.13
|
Release files / dash_prefix-0.0.4-py3-none-any.whl
| Download URL | dash_prefix-0.0.4-py3-none-any.whl |
|---|---|
| Size | 7.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0fc3423a1d79d8ac4cfca22b1fb317fb3b90ae9a326f144e8205e84492024a8c
|
|
BLAKE2b-256 checksum How to use checksums |
4ace92e52630a0e85fbd0403b4bdfe19444226f5aa9c023eb9856677e02510d7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.11.4 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.64.0 CPython/3.8.13
|
Security for dash-prefix 0.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.