PyGWalker Spec 파일
PyGWalker spec은 차트 상태를 저장합니다. PyGWalker가 로컬 파일에서 로드하거나 로컬 파일에 저장해야 할 때는 spec_path를 사용하고, 인라인 JSON, config ID, 원격 spec에는 spec을 사용하세요.
import pygwalker as pyg
walker = pyg.walk(
df,
spec_path="./gw_config.json",
computation="browser",
)spec_path vs spec
| 옵션 | 용도 | 예시 |
|---|---|---|
spec_path | 로컬 차트 상태 파일 | spec_path="./gw_config.json" |
spec | 인라인 JSON, config ID, 원격 spec URL | spec='[{"name":"Chart 1", ...}]' |
새 로컬 파일 예제에는 spec_path를 권장합니다. 파일 지속성을 명확히 하고 인라인 JSON 또는 원격 spec과의 모호함을 피할 수 있습니다.
차트 상태 저장 및 재사용
어댑터가 저장 기능을 제공할 때는 read-write spec 모드를 사용하세요.
import pygwalker as pyg
walker = pyg.Walker(
df,
spec_path="./gw_config.json",
spec_io_mode="rw",
computation="kernel",
)
walker.show()Streamlit과 Gradio도 spec_io_mode를 지원합니다.
from pygwalker.api.streamlit import StreamlitRenderer
renderer = StreamlitRenderer(
df,
spec_path="./gw_config.json",
spec_io_mode="rw",
computation="kernel",
)
renderer.explorer()저장된 차트 렌더링
전체 탐색기 없이 저장된 차트를 보고 싶다면 render를 사용하세요.
import pygwalker as pyg
pyg.render(df, spec_path="./gw_config.json", computation="browser")정적 renderer 내보내기에는 to_render_html을 사용하세요.
from pygwalker.api.html import to_render_html
html = to_render_html(df, spec_path="./gw_config.json", computation="browser")이전 spec 마이그레이션
pygwalker.spec.migrate는 저장된 PyGWalker 또는 Graphic Walker spec을 현재 schema 형태로 업데이트합니다.
import json
import pygwalker as pyg
migrated = pyg.spec.migrate("./old_gw_config.json")
with open("./gw_config.json", "w", encoding="utf-8") as f:
json.dump(migrated, f, ensure_ascii=False, indent=2)시그니처:
pygwalker.spec.migrate(spec, *, version=None) -> dictspec은 다음을 받을 수 있습니다.
| 입력 | 허용 여부 |
|---|---|
| 로드된 Python 객체 | dict 또는 list |
| JSON 문자열 | 예 |
| 기존 로컬 파일 경로 | 예 |
문자열이 잘못된 JSON처럼 보이거나 파일 경로가 존재하지 않으면 migrate가 ValueError를 발생시킵니다.
흔한 함정
| 함정 | 해결 |
|---|---|
새 코드에서 로컬 파일을 spec으로 전달 | spec_path를 사용하세요. |
정적 HTML이 편집 내용을 spec_path에 다시 저장한다고 기대 | 저장을 지원하는 라이브 노트북/앱 백엔드를 사용하세요. |
이미 Walker를 받은 어댑터에 spec_path 전달 | 원래 Walker에 spec 경로를 지정하세요. |
원격 spec URL을 spec.migrate로 마이그레이션 | 먼저 spec 객체를 로드한 뒤 객체 또는 JSON 문자열을 전달하세요. |