Skip to content
PYGWALKER
API 참조
Gradio

PyGWalker Gradio API

Gradio 앱용 PyGWalker iframe HTML을 만들려면 get_html_on_gradio를 사용하세요. 앱을 실행할 때 PYGWALKER_ROUTE를 마운트해 PyGWalker 통신 라우트를 사용할 수 있게 해야 합니다.

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

시그니처:

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은 pandas DataFrame, polars DataFrame, pyarrow Table 또는 데이터베이스 Connector일 수 있습니다.

주요 옵션

옵션기본값참고
spec_pathNone로컬 차트 상태 파일입니다. 로컬 파일에는 이 옵션을 권장합니다.
spec_io_mode"r"Gradio UI에서 차트 편집 내용을 저장해야 하면 "rw"를 사용하세요.
computationNone명시적으로 선택하려면 "browser", "kernel", "cloud"를 사용하세요.
kernel_computationNone레거시 호환성 플래그입니다. computation을 권장하며, PyGWalker 0.7.0에서 제거될 예정입니다.
default_tab"vis"초기 탐색기 탭입니다.

계산 참고

Gradio는 라이브 앱으로 실행되므로 kernel 및 cloud 계산을 지원합니다.

get_html_on_gradio(df, computation="browser")
get_html_on_gradio(df, computation="kernel")
get_html_on_gradio(df, computation="cloud", kanaries_api_key="...")

non-auto computation 값과 활성화된 레거시 계산 플래그를 함께 사용하지 마세요. 옵션이 충돌하면 PyGWalker가 ValueError를 발생시킵니다.

흔한 함정

함정해결
iframe은 렌더링되지만 상호작용이 실패app_kwargs={"routes": [PYGWALKER_ROUTE]}로 실행하세요.
로컬 차트 편집 내용이 저장되지 않음spec_pathspec_io_mode="rw"를 함께 사용하세요.
새 코드에서 kernel_computation=True 사용computation="kernel"을 사용하세요.
Gradio 앱 대신 정적 HTML 내보내기가 필요HTML 내보내기에서 computation="browser"를 사용하세요.

관련 가이드