API de exportación HTML de PyGWalker
Usa pygwalker.to_html(...) cuando necesites una cadena HTML estática. Las exportaciones estáticas son solo browser: no admiten computación kernel ni cloud activa.
import pygwalker as pyg
html = pyg.to_html(
df,
spec_path="./gw_config.json",
computation="browser",
)Limitación del HTML estático
El HTML estático no tiene un kernel Python activo ni callback cloud. PyGWalker rechaza:
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)Usa computation="browser" u omite la opción de computación. Usa API para notebooks, Streamlit, Gradio o el modo webserver cuando necesites computación kernel o cloud activa.
pygwalker.to_html
to_html devuelve una cadena HTML iframe incrustable.
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")Firma:
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 puede ser un pandas DataFrame, polars DataFrame, pyarrow Table o pygwalker.Walker reutilizable.
Exporta desde un Walker reutilizable
Crea un Walker cuando el mismo estado de gráficos también deba renderizarse en notebooks o 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")Cuando to_html recibe un Walker, pasa las dimensiones de renderizado como argumentos keyword width y height. Las opciones de construcción como spec_path, field_specs, appearance y computation deben configurarse en el Walker original.
walker.to_html(iframe_width=None, iframe_height=None) y walker.to_html_without_iframe() ofrecen el mismo comportamiento de exportación estática y también rechazan computación kernel/cloud activa.
Helpers de tabla y renderer
Usa estos helpers cuando no necesites el explorador completo.
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")Firmas:
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,
) -> strHelper de previsualización de gráficos
to_chart_html renderiza un solo gráfico desde una spec de Graphic Walker o Vega.
from pygwalker.api.html import to_chart_html
chart_html = to_chart_html(
df,
spec=chart_spec,
spec_type="graphic-walker",
)Firma:
to_chart_html(
dataset,
spec,
*,
spec_type="graphic-walker",
theme_key="g2",
appearance="media",
) -> strdataset puede ser un DataFrame, pyarrow Table, Connector de base de datos o cadena con estilo de conector.
Errores comunes
| Error | Solución |
|---|---|
| Exportar datos locales grandes con computación kernel | Usa un backend activo en lugar de HTML estático. |
Pasar un Walker más spec_path a to_html | Coloca spec_path en pyg.Walker(...). |
Empezar ejemplos estáticos nuevos con kernel_computation=True | Usa computation="browser". |
| Esperar que los usuarios editen y guarden estado de gráficos en una exportación estática | Usa un backend activo de notebook/app con spec_io_mode="rw". |