Browser capture & custom renderer pipeline for Plotly Dash components
Project description
dash-capture
Plotly figures in Dash are rendered by JavaScript in the browser — the Python server never holds the chart as pixels. dash-capture bridges this gap by triggering the capture directly in the running browser, with no server-side headless browser (Chrome, Playwright, webshot2) required. The result is delivered to Python for post-processing, custom rendering, and download.
Installation
pip install dash-capture
Usage
High-level — one-line wizard with form, preview, and download
from dash_capture import capture_graph, plotly_strategy
# Returns an html.Div — place it next to your dcc.Graph
capture_graph(
graph="my-graph",
trigger="Export",
strip_title=True,
width=2400,
height=1600,
)
Clicking the trigger opens a modal with editable fields, a live preview, and a download button.
Low-level — wire capture to your own UI
from dash_capture import capture_binding, plotly_strategy
binding = capture_binding(
"my-graph",
strategy=plotly_strategy(strip_title=True, width=2400),
trigger=Input("my-btn", "n_clicks"),
)
# Place binding.store in the layout
# React to binding.store_id to get the base64 PNG
Custom renderer
def my_renderer(_target, _snapshot_img, title: str = ""):
"""_target: file-like, _snapshot_img: callable → raw PNG bytes."""
png = _snapshot_img()
# post-process: add watermark, corporate frame, etc.
_target.write(png)
capture_graph("my-graph", renderer=my_renderer)
Strategies
| Strategy | Method | Use case |
|---|---|---|
plotly_strategy() |
Plotly.toImage() |
Plotly charts — exact resolution |
html2canvas_strategy() |
html2canvas | Any DOM element |
canvas_strategy() |
canvas.toDataURL() |
Raw <canvas> elements |
Strip patches remove chart decorations before capture without touching the live chart:
plotly_strategy(
strip_title=True,
strip_legend=True,
strip_margin=True,
width=2400,
height=1600,
format="png", # or "jpeg", "webp", "svg"
)
Pre-filling fields from the live figure
FromPlotly reads a value from the running Plotly figure to pre-populate form fields — no re-typing needed:
from dash_capture import capture_graph, FromPlotly
capture_graph(
"my-graph",
title=FromPlotly("layout.title.text"), # reads current title
sources="Internal data",
)
License
MIT
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
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_capture-0.0.6.tar.gz.
File metadata
- Download URL: dash_capture-0.0.6.tar.gz
- Upload date:
- Size: 672.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba91ac947f7d8814cb195aa3c2d21e9764d99efc612d1bdf30648d9298c9d292
|
|
| MD5 |
fae21b286086fd052ef45c594ef21ba3
|
|
| BLAKE2b-256 |
fa467fbbb7fc8c7f188801b7faee26238da3ea60b56dc823d9d75ca09ff98e5a
|
Provenance
The following attestation bundles were made for dash_capture-0.0.6.tar.gz:
Publisher:
publish.yml on saemeon/dash-capture
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dash_capture-0.0.6.tar.gz -
Subject digest:
ba91ac947f7d8814cb195aa3c2d21e9764d99efc612d1bdf30648d9298c9d292 - Sigstore transparency entry: 1207550466
- Sigstore integration time:
-
Permalink:
saemeon/dash-capture@1b47ae39959d1c0cee3f84f591e52ecc3e702a0f -
Branch / Tag:
refs/tags/v0.0.6 - Owner: https://github.com/saemeon
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1b47ae39959d1c0cee3f84f591e52ecc3e702a0f -
Trigger Event:
release
-
Statement type:
File details
Details for the file dash_capture-0.0.6-py3-none-any.whl.
File metadata
- Download URL: dash_capture-0.0.6-py3-none-any.whl
- Upload date:
- Size: 71.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3a858071947187752c50b7efe2e2bec15486ed1f370fbbfa58c016b24a35a58e
|
|
| MD5 |
c538e4340066273deefe824a39f30129
|
|
| BLAKE2b-256 |
14a713d97379a14fb451fc1528493e2e52a6742acc5582642eba0efc430080b7
|
Provenance
The following attestation bundles were made for dash_capture-0.0.6-py3-none-any.whl:
Publisher:
publish.yml on saemeon/dash-capture
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dash_capture-0.0.6-py3-none-any.whl -
Subject digest:
3a858071947187752c50b7efe2e2bec15486ed1f370fbbfa58c016b24a35a58e - Sigstore transparency entry: 1207550562
- Sigstore integration time:
-
Permalink:
saemeon/dash-capture@1b47ae39959d1c0cee3f84f591e52ecc3e702a0f -
Branch / Tag:
refs/tags/v0.0.6 - Owner: https://github.com/saemeon
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1b47ae39959d1c0cee3f84f591e52ecc3e702a0f -
Trigger Event:
release
-
Statement type: