Skip to content

PlotlyChart

Render a Plotly figure through Hedron's bounded adapter pipeline.

Import from hedron_charts import PlotlyChart
Distribution hedron-charts[plotly]
Backend activity No
Normal render mode RenderMode.FRAGMENT

Live demo

PlotlyChart outputAccessible static preview with a text conclusion.

The preview is a local docs simulation (not a running Hedron server). Interactive demos show a “Simulated HTMX” trace when applicable.

Install the optional provider before importing this component:

pip install "hedron-charts[plotly]>=1.0.0,<2.0"

Basic use

from hedron_charts import PlotlyChart
import plotly.graph_objects as go
fig = go.Figure(data=[go.Bar(x=['IAD', 'PDX'], y=[120, 80])])

component = PlotlyChart(fig, title='Requests by region', description='US East handles the largest share.')

Compose under Page for full documents, or return from a fragment route for HTMX swaps.

How it works

The adapter compiles the figure into the supported static or browser representation, enforces visualization limits, and attaches accessible metadata and fallback content.

The server emits bounded, non-executable JSON and accessible metadata. The interactive visual requires the corresponding vendored browser host/runtime; these adapters remain Experimental and fail closed when the runtime is unavailable.

Constructor and parameters

PlotlyChart(figure, *, title=None, description=None, alt=None, waiver=None)
Parameter Type Meaning
figure Plotly figure Figure specification.
title / description / alt str | None Accessible metadata.
waiver str | None Reviewed exception.

Composition and backend behavior

Keep PlotlyChart at the smallest semantic boundary. Fragment routes should return only the replaced region and preserve stable target IDs across success, validation, empty, loading, and error responses.

PlotlyChart renders data the server already prepared. Keep queries, authorization, and redaction on the route or data source — do not treat the component as a place for side effects.

Accessibility

Make hover-only values available through labels or a table and ensure keyboard users can reach any enabled controls.

Security

Escaping and SafeUrl / TrustedHtml are framework concerns; authorization and data exposure remain application code. Redact secrets before rendering.

Common mistakes

  • Do not pass untrusted custom HTML, JavaScript callbacks, or unbounded traces.
  • Do not copy docs-preview JavaScript into an application server.

Testing

from hedron import RenderMode, render

result = render(component, mode=RenderMode.FRAGMENT)
assert result.html
assert not result.diagnostics

Charts guide · Charts API · hedron-charts package