Utilities for providing convenient methods to serve cached data in Plotly-Dash or Flask.
Project description
Dash File Cache
Dash File Cache is a Dash extension library.
Utilities for providing convenient methods to serve cached data in Plotly-Dash or Flask.
The data cache enables the following features:
- Load a server-side file dynamically and send the file to users (the frontend).
- Support in-memory files (like
io.BytesIO()) or on-disk files (specified by a path). - Support different kinds of cache (single-thread, multi-processing, or file-based).
- Customized components helping the dashboard trigger download events from the server side.
1. Install
Intall the latest released version of this package by using the PyPI source:
python -m pip install dash-file-cache
If users want to install the developer's version, they need to ensure that the following packages are installed.
Then use the following commands to install it.
git clone --depth 1 --single-branch https://github.com/cainmagi/dash-file-cache
cd dash-file-cache
python -m pip install -r requirements.txt -r requirements-dev.txt
yarn install
yarn dlx @yarnpkg/sdks vscode
yarn build
python -m pip install .[dev]
For VSCode users, please install the recommended extensions specified in the project workspace file.
2. Usage
The following codes show a minimal example of this package
from typing import Optional
import io
import dash
from dash import html
from dash import Input, Output
from dash_file_cache import ServiceData, CachePlain
app = dash.Dash("demo")
service = ServiceData(CachePlain(1))
service.serve(app)
app.layout = html.Div(
(
html.Div(
html.P(
(
html.Span("Get Image:", style={"paddingRight": "0.5rem"}),
html.Button(id="btn", children="Image"),
)
)
),
html.Div((html.P("Cache address:"), html.P(id="addr"))),
html.Div((html.P("Cached Image:"), html.Img(id="cache"))),
),
)
@app.callback(
Output("addr", "children"),
Input("btn", "n_clicks"),
prevent_initial_call=True,
)
def click_get_image(
n_clicks: Optional[int],
):
if not n_clicks:
return dash.no_update
addr = service.register(
io.StringIO(
R'<svg height="100" width="100" xmlns="http://www.w3.org/2000/svg">'
R'<circle r="45" cx="50" cy="50" fill="red" /></svg>'
),
content_type="image/svg+xml",
mime_type="image/svg+xml",
one_time_service=True,
)
return addr
@app.callback(
Output("cache", "src"),
Input("addr", "children"),
prevent_initial_call=True,
)
def update_cache(addr):
if not addr:
return dash.no_update
return addr
if __name__ == "__main__":
app.run(host="127.0.0.1", port="8080", debug=True)
Check http://127.0.0.1:8080 to see the following results:
| The minimal demo |
|---|
3. Documentation
Check the documentation to find more details about the examples and APIs.
https://cainmagi.github.io/dash-file-cache/
4. Contributing
5. Changelog
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dash_file_cache-0.2.0.tar.gz.
File metadata
- Download URL: dash_file_cache-0.2.0.tar.gz
- Upload date:
- Size: 369.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5a367233e138fa8767b5489645aa8f46184aa9fa1339001f89b3797d73fdb203
|
|
| MD5 |
1cd1ca6377fd69d50e31b70429c9517d
|
|
| BLAKE2b-256 |
cf6c482fbf9ca381cde01a1d69c105217ad9854f55aba6f501d5cc28947ec799
|
Provenance
The following attestation bundles were made for dash_file_cache-0.2.0.tar.gz:
Publisher:
python-publish.yml on cainmagi/dash-file-cache
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dash_file_cache-0.2.0.tar.gz -
Subject digest:
5a367233e138fa8767b5489645aa8f46184aa9fa1339001f89b3797d73fdb203 - Sigstore transparency entry: 190514058
- Sigstore integration time:
-
Permalink:
cainmagi/dash-file-cache@c9d72d824d70274d2c931a98b1235de034cc5dd6 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/cainmagi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@c9d72d824d70274d2c931a98b1235de034cc5dd6 -
Trigger Event:
release
-
Statement type:
File details
Details for the file dash_file_cache-0.2.0-py3-none-any.whl.
File metadata
- Download URL: dash_file_cache-0.2.0-py3-none-any.whl
- Upload date:
- Size: 130.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6bca75f87de23ea96a548c6e96eef1b7c5e5f734d92198a80a68108ae2292001
|
|
| MD5 |
b90506d198c34f5598688a416271c15f
|
|
| BLAKE2b-256 |
4e5d8982cc9f3f71c5759c6213858938b4952ea1846d0165e9f266bcdc015f62
|
Provenance
The following attestation bundles were made for dash_file_cache-0.2.0-py3-none-any.whl:
Publisher:
python-publish.yml on cainmagi/dash-file-cache
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dash_file_cache-0.2.0-py3-none-any.whl -
Subject digest:
6bca75f87de23ea96a548c6e96eef1b7c5e5f734d92198a80a68108ae2292001 - Sigstore transparency entry: 190514060
- Sigstore integration time:
-
Permalink:
cainmagi/dash-file-cache@c9d72d824d70274d2c931a98b1235de034cc5dd6 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/cainmagi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@c9d72d824d70274d2c931a98b1235de034cc5dd6 -
Trigger Event:
release
-
Statement type: