PyGWalker HTML エクスポート API
静的 HTML 文字列が必要な場合は pygwalker.to_html(...) を使います。静的エクスポートはブラウザー専用です。ライブ kernel や cloud computation はサポートしません。
import pygwalker as pyg
html = pyg.to_html(
df,
spec_path="./gw_config.json",
computation="browser",
)静的 HTML の制限
静的 HTML にはライブ Python kernel もクラウドコールバックもありません。PyGWalker は次を拒否します。
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)computation="browser" を使うか computation オプションを省略します。ライブ kernel や cloud computation が必要な場合は、ノートブック API、Streamlit、Gradio、または webserver mode を使います。
pygwalker.to_html
to_html は埋め込み可能な iframe HTML 文字列を返します。
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 には pandas DataFrame、polars DataFrame、pyarrow Table、または再利用可能な pygwalker.Walker を渡せます。
再利用可能な Walker からエクスポートする
同じチャート状態を notebook やアプリでもレンダリングしたい場合は Walker を作成します。
import pygwalker as pyg
walker = pyg.Walker(
df,
spec_path="./gw_config.json",
computation="browser",
)
html = pyg.to_html(walker, width="100%", height="720px")to_html が Walker を受け取る場合、レンダリング寸法は width と height キーワード引数で渡します。spec_path、field_specs、appearance、computation などの構築オプションは元の Walker に設定する必要があります。
walker.to_html(iframe_width=None, iframe_height=None) と walker.to_html_without_iframe() は同じ静的エクスポート挙動を提供し、ライブ kernel / cloud computation も拒否します。
テーブルと renderer helper
explorer 全体が不要な場合は、これらの helper を使います。
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
to_chart_html は Graphic Walker または 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 には DataFrame、pyarrow Table、データベース Connector、または Connector 形式文字列を渡せます。
よくある落とし穴
| 落とし穴 | 修正方法 |
|---|---|
| 大きなローカルデータを kernel computation でエクスポートする | 静的 HTML ではなくライブバックエンドを使います。 |
Walker と spec_path を一緒に to_html へ渡す | spec_path は pyg.Walker(...) 側に置きます。 |
新しい静的例を kernel_computation=True で始める | computation="browser" を使います。 |
| ユーザーが静的エクスポート内でチャート状態を編集して保存できると期待する | spec_io_mode="rw" を備えたライブ notebook / app バックエンドを使います。 |