Skip to main content

Browser capture & custom renderer pipeline for Plotly Dash components

Project description

PyPI Python License Plotly Dash Ruff uv ty prek

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

dash_capture-0.0.6.tar.gz (672.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_capture-0.0.6-py3-none-any.whl (71.0 kB view details)

Uploaded Python 3

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

Hashes for dash_capture-0.0.6.tar.gz
Algorithm Hash digest
SHA256 ba91ac947f7d8814cb195aa3c2d21e9764d99efc612d1bdf30648d9298c9d292
MD5 fae21b286086fd052ef45c594ef21ba3
BLAKE2b-256 fa467fbbb7fc8c7f188801b7faee26238da3ea60b56dc823d9d75ca09ff98e5a

See more details on using hashes here.

Provenance

The following attestation bundles were made for dash_capture-0.0.6.tar.gz:

Publisher: publish.yml on saemeon/dash-capture

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_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

Hashes for dash_capture-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 3a858071947187752c50b7efe2e2bec15486ed1f370fbbfa58c016b24a35a58e
MD5 c538e4340066273deefe824a39f30129
BLAKE2b-256 14a713d97379a14fb451fc1528493e2e52a6742acc5582642eba0efc430080b7

See more details on using hashes here.

Provenance

The following attestation bundles were made for dash_capture-0.0.6-py3-none-any.whl:

Publisher: publish.yml on saemeon/dash-capture

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