PyGWalker Gradio API
Use get_html_on_gradio to generate PyGWalker iframe HTML for a Gradio app. Mount PYGWALKER_ROUTE when launching the app so PyGWalker communication routes are available.
import gradio as gr
import pandas as pd
from pygwalker.api.gradio import PYGWALKER_ROUTE, get_html_on_gradio
df = pd.read_csv("data.csv")
with gr.Blocks() as demo:
pyg_html = get_html_on_gradio(
df,
spec_path="./gw_config.json",
spec_io_mode="rw",
computation="kernel",
)
gr.HTML(pyg_html)
demo.launch(app_kwargs={"routes": [PYGWALKER_ROUTE]})get_html_on_gradio
Signature:
get_html_on_gradio(
dataset,
gid=None,
*,
field_specs=None,
theme_key="g2",
appearance="media",
spec="",
spec_path=None,
spec_io_mode="r",
computation=None,
kernel_computation=None,
kanaries_api_key="",
default_tab="vis",
**kwargs,
) -> strdataset can be a pandas DataFrame, polars DataFrame, pyarrow Table, or database Connector.
Key options
| Option | Default | Notes |
|---|---|---|
spec_path | None | Local chart-state file. Prefer this for local files. |
spec_io_mode | "r" | Use "rw" when the Gradio UI should save chart edits. |
computation | None | Use "browser", "kernel", or "cloud" to choose explicitly. |
kernel_computation | None | Legacy compatibility flag. Prefer computation; removal is scheduled for PyGWalker 0.7.0. |
default_tab | "vis" | Initial explorer tab. |
Computation notes
Gradio runs as a live app, so kernel and cloud computation are supported.
get_html_on_gradio(df, computation="browser")
get_html_on_gradio(df, computation="kernel")
get_html_on_gradio(df, computation="cloud", kanaries_api_key="...")Do not mix a non-auto computation value with enabled legacy computation flags. PyGWalker raises ValueError when those options conflict.
Common traps
| Trap | Fix |
|---|---|
| The iframe renders but interactions fail | Launch with app_kwargs={"routes": [PYGWALKER_ROUTE]}. |
| Local chart edits are not saved | Use spec_path plus spec_io_mode="rw". |
New code uses kernel_computation=True | Use computation="kernel". |
| A static HTML export is needed instead of a Gradio app | Use HTML Exports with computation="browser". |