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.7.tar.gz (672.9 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.7-py3-none-any.whl (71.6 kB view details)

Uploaded Python 3

File details

Details for the file dash_capture-0.0.7.tar.gz.

File metadata

  • Download URL: dash_capture-0.0.7.tar.gz
  • Upload date:
  • Size: 672.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for dash_capture-0.0.7.tar.gz
Algorithm Hash digest
SHA256 99edbdbbcb5ed96f78e8cfeaa53dc6cc640e0cd5bab3969edb17dd92b5a3d7f4
MD5 6700d00d3d48b44188510714fd14546f
BLAKE2b-256 afefe68fe0c5a275ee4c62e5f4986c8e5f95554c6bed075ffd48475cf50f595d

See more details on using hashes here.

Provenance

The following attestation bundles were made for dash_capture-0.0.7.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.7-py3-none-any.whl.

File metadata

  • Download URL: dash_capture-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 71.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for dash_capture-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 d3f0a0e5b1d984a73684c4c560b6d67771617a82b8da78ff54a49ed660e59c9f
MD5 ac9c2671e2d372fd69bd74f9373fb89c
BLAKE2b-256 3cae881cd51bbb0114bc211bc797d115a38ca8e894d80b734e1d53e1eff5e7a6

See more details on using hashes here.

Provenance

The following attestation bundles were made for dash_capture-0.0.7-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