Skip to content

PyGWalker HTML 내보내기 API

정적 HTML 문자열이 필요하면 pygwalker.to_html(...)을 사용하세요. 정적 내보내기는 브라우저 전용입니다. 라이브 kernel 또는 cloud 계산을 지원하지 않습니다.

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"를 사용하거나 계산 옵션을 생략하세요. 라이브 kernel 또는 cloud 계산이 필요하면 노트북 API, Streamlit, Gradio 또는 웹서버 모드를 사용하세요.

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

시그니처:

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는 pandas DataFrame, polars DataFrame, pyarrow Table 또는 재사용 가능한 pygwalker.Walker일 수 있습니다.

재사용 가능한 Walker에서 내보내기

같은 차트 상태를 노트북이나 앱에서도 렌더링해야 한다면 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_htmlWalker를 받으면 렌더링 크기를 widthheight 키워드 인자로 전달하세요. spec_path, field_specs, appearance, computation 같은 생성 옵션은 원래 Walker에 설정해야 합니다.

walker.to_html(iframe_width=None, iframe_height=None)walker.to_html_without_iframe()도 같은 정적 내보내기 동작을 제공하며, 라이브 kernel/cloud 계산 역시 거부합니다.

테이블 및 renderer 헬퍼

전체 탐색기가 필요하지 않을 때는 다음 헬퍼를 사용하세요.

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

시그니처:

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

차트 미리보기 헬퍼

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

시그니처:

to_chart_html(
    dataset,
    spec,
    *,
    spec_type="graphic-walker",
    theme_key="g2",
    appearance="media",
) -> str

dataset은 DataFrame, pyarrow Table, 데이터베이스 Connector 또는 connector 스타일 문자열일 수 있습니다.

흔한 함정

함정해결
큰 로컬 데이터를 kernel 계산으로 내보내기정적 HTML 대신 라이브 백엔드를 사용하세요.
Walkerspec_path를 함께 to_html에 전달spec_pathpyg.Walker(...)에 지정하세요.
새 정적 예제를 kernel_computation=True로 시작computation="browser"를 사용하세요.
사용자가 정적 내보내기에서 차트 상태를 편집하고 저장할 수 있다고 기대저장을 지원하는 라이브 노트북/앱 백엔드를 사용하세요.

관련 가이드