Export, Dash & Performance
Exporting
fig.write_html('chart.html') # standalone interactive HTML
fig.write_image('chart.png') # static image — needs: pip install kaleido
# For a report with MANY charts, load Plotly.js once from a CDN instead
# of embedding a full copy (several hundred KB) in every single file
fig.write_html('report.html', include_plotlyjs='cdn')Large Datasets — WebGL
# Standard Scatter renders every point as an individual SVG element —
# slow to pan/zoom/hover at hundreds of thousands of points
fig = px.scatter(huge_df, x='x', y='y', render_mode='webgl')
# or explicitly: go.Scattergl(x=x, y=y) — renders on the GPU insteadDash
from dash import Dash, dcc, html, Input, Output
app = Dash(__name__)
app.layout = html.Div([
dcc.Dropdown(id='metric', options=['revenue', 'users'], value='revenue'),
dcc.Graph(id='chart'),
])
@app.callback(Output('chart', 'figure'), Input('metric', 'value'))
def update_chart(metric):
# Runs SERVER-SIDE on every dropdown change — a round trip, unlike a
# standalone figure's client-side-only hover/zoom/pan interactivity
return px.line(df, x='date', y=metric)
app.run(debug=True)Keep your own version of these notes — editable, searchable, and organised by your stack.
Start free