openseries.export_plotly_figure
- openseries.export_plotly_figure(figure, fig_config, output_type, filename, *, include_plotlyjs, auto_open=False, plotfile, title=None, logo_url=None)[source]
Export a Plotly figure to a mobile-responsive HTML file or inline div.
This function converts a Plotly figure to HTML output, with support for mobile-responsive standalone HTML files or inline HTML divs. When exporting to a file, the output includes proper viewport settings, responsive CSS, and JavaScript for handling window resizing and orientation changes.
- Parameters:
figure (Figure) – Plotly figure to render.
fig_config (PlotlyConfigType) – Plotly config dictionary.
output_type (LiteralPlotlyOutput) – Output type:
"file"or"div".filename (str) – Output filename used for the
div_idwhen inline, or to derive the div_id when exporting to file.include_plotlyjs (LiteralPlotlyJSlib) – How plotly.js is included. Can be
True(inline),False(not included), or"cdn"(CDN link).auto_open (bool) – Whether to auto-open the file in a browser (only used when
output_type="file"). Defaults toFalse.plotfile (Path | str) – Full path to the output HTML file. Required when
output_type="file", ignored whenoutput_type="div".title (str | None) – Title for the HTML page (used for file output). Defaults to
None.logo_url (str | None) – Optional logo URL to display in the title container. Defaults to
None.
- Returns:
If
output_typeis"file", the path to the file as a string; otherwise an inline HTML string (div).- Return type:
Example
Export a Plotly figure to a responsive HTML file:
>>> import plotly.graph_objects as go >>> from openseries.html_utils import export_plotly_figure >>> from pathlib import Path >>> >>> fig = go.Figure(data=go.Scatter(x=[1, 2, 3], y=[4, 5, 6])) >>> output_path = export_plotly_figure( ... figure=fig, ... fig_config={}, ... output_type="file", ... filename="my_plot.html", ... include_plotlyjs="cdn", ... plotfile=Path("output/my_plot.html"), ... title="My Plot", ... auto_open=True, ... )