Skip to content

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

dataset can be a pandas DataFrame, polars DataFrame, pyarrow Table, or database Connector.

Key options

OptionDefaultNotes
spec_pathNoneLocal chart-state file. Prefer this for local files.
spec_io_mode"r"Use "rw" when the Gradio UI should save chart edits.
computationNoneUse "browser", "kernel", or "cloud" to choose explicitly.
kernel_computationNoneLegacy 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

TrapFix
The iframe renders but interactions failLaunch with app_kwargs={"routes": [PYGWALKER_ROUTE]}.
Local chart edits are not savedUse spec_path plus spec_io_mode="rw".
New code uses kernel_computation=TrueUse computation="kernel".
A static HTML export is needed instead of a Gradio appUse HTML Exports with computation="browser".

Related Guides