PyGWalker HTML Export API
Use pygwalker.to_html(...) when you need a static HTML string. Static exports are browser-only: they do not support live kernel or cloud computation.
import pygwalker as pyg
html = pyg.to_html(
df,
spec_path="./gw_config.json",
computation="browser",
)Static HTML limitation
Static HTML has no live Python kernel and no cloud callback. PyGWalker rejects:
pyg.to_html(df, computation="kernel")
pyg.to_html(df, computation="cloud")
pyg.to_html(df, kernel_computation=True)
pyg.to_html(df, cloud_computation=True)
pyg.to_html(df, use_kernel_calc=True)Use computation="browser" or omit the computation option. Use Notebook APIs, Streamlit, Gradio, or webserver mode when you need live kernel or cloud computation.
pygwalker.to_html
to_html returns an embeddable iframe HTML string.
import pathlib
import pygwalker as pyg
html = pyg.to_html(df, spec_path="./gw_config.json", computation="browser")
pathlib.Path("pygwalker.html").write_text(html, encoding="utf-8")Signature:
pyg.to_html(
df,
gid=None,
*,
spec="",
spec_path=None,
field_specs=None,
theme_key="g2",
appearance="media",
default_tab="vis",
computation=None,
**kwargs,
) -> strdf can be a pandas DataFrame, polars DataFrame, pyarrow Table, or reusable pygwalker.Walker.
Export from a reusable Walker
Create a Walker when the same chart state should also render in notebooks or apps.
import pygwalker as pyg
walker = pyg.Walker(
df,
spec_path="./gw_config.json",
computation="browser",
)
html = pyg.to_html(walker, width="100%", height="720px")When to_html receives a Walker, pass rendering dimensions as width and height keyword arguments. Construction options such as spec_path, field_specs, appearance, and computation must be set on the original Walker.
walker.to_html(iframe_width=None, iframe_height=None) and walker.to_html_without_iframe() provide the same static-export behavior and also reject live kernel/cloud computation.
Table and renderer helpers
Use these helpers when you do not need the full explorer.
from pygwalker.api.html import to_table_html, to_render_html
table_html = to_table_html(df, spec_path="./gw_config.json", computation="browser")
render_html = to_render_html(df, spec_path="./gw_config.json", computation="browser")Signatures:
to_table_html(
df,
*,
spec_path=None,
theme_key="g2",
appearance="media",
computation=None,
**kwargs,
) -> str
to_render_html(
df,
spec="",
*,
spec_path=None,
theme_key="g2",
appearance="media",
computation=None,
**kwargs,
) -> strChart preview helper
to_chart_html renders a single chart from a Graphic Walker or Vega spec.
from pygwalker.api.html import to_chart_html
chart_html = to_chart_html(
df,
spec=chart_spec,
spec_type="graphic-walker",
)Signature:
to_chart_html(
dataset,
spec,
*,
spec_type="graphic-walker",
theme_key="g2",
appearance="media",
) -> strdataset can be a DataFrame, pyarrow Table, database Connector, or connector-style string.
Common traps
| Trap | Fix |
|---|---|
| Exporting large local data with kernel computation | Use a live backend instead of static HTML. |
Passing a Walker plus spec_path to to_html | Put spec_path on pyg.Walker(...). |
Starting new static examples with kernel_computation=True | Use computation="browser". |
| Expecting users to edit and save chart state in a static export | Use a live notebook/app backend with spec_io_mode="rw". |