Skip to content
PYGWALKER
Référence de l'API
Exports HTML

API d'export HTML PyGWalker

Utilisez pygwalker.to_html(...) lorsque vous avez besoin d'une chaîne HTML statique. Les exports statiques sont browser-only : ils ne prennent pas en charge le calcul kernel ou cloud en direct.

import pygwalker as pyg
 
html = pyg.to_html(
    df,
    spec_path="./gw_config.json",
    computation="browser",
)

Limitation du HTML statique

Le HTML statique n'a pas de kernel Python actif ni de callback cloud. PyGWalker refuse :

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)

Utilisez computation="browser" ou omettez l'option de calcul. Utilisez API Notebook, Streamlit, Gradio ou le mode webserver lorsque vous avez besoin de calcul kernel ou cloud en direct.

pygwalker.to_html

to_html retourne une chaîne HTML iframe intégrable.

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,
) -> str

df peut être une DataFrame pandas, une DataFrame polars, une pyarrow Table ou un pygwalker.Walker réutilisable.

Exporter depuis un Walker réutilisable

Créez un Walker lorsque le même état de graphique doit aussi être rendu dans des notebooks ou applications.

import pygwalker as pyg
 
walker = pyg.Walker(
    df,
    spec_path="./gw_config.json",
    computation="browser",
)
 
html = pyg.to_html(walker, width="100%", height="720px")

Lorsque to_html reçoit un Walker, passez les dimensions de rendu avec les arguments nommés width et height. Les options de construction comme spec_path, field_specs, appearance et computation doivent être définies sur le Walker d'origine.

walker.to_html(iframe_width=None, iframe_height=None) et walker.to_html_without_iframe() fournissent le même comportement d'export statique et refusent aussi le calcul kernel/cloud en direct.

Helpers table et renderer

Utilisez ces helpers lorsque vous n'avez pas besoin de l'explorateur complet.

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,
) -> str

Helper d'aperçu de graphique

to_chart_html rend un seul graphique à partir d'une spec Graphic Walker ou Vega.

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",
) -> str

dataset peut être une DataFrame, une pyarrow Table, un Connector de base de données ou une chaîne de style connecteur.

Pièges courants

PiègeCorrection
Exporter de grandes données locales avec le calcul kernelUtilisez un backend actif au lieu de HTML statique.
Passer un Walker avec spec_path à to_htmlPlacez spec_path dans pyg.Walker(...).
Commencer de nouveaux exemples statiques avec kernel_computation=TrueUtilisez computation="browser".
S'attendre à ce que les utilisateurs modifient et enregistrent l'état des graphiques dans un export statiqueUtilisez un backend notebook/app actif avec spec_io_mode="rw".

Guides associés