PyGWalker HTML API Guide
PyGWalker allows you to render the Graphic Walker UI in any application that supports HTML rendering. This guide explains how to use the HTML API effectively.
Important Note
The current HTML API is designed for front-end computation only. It may not be suitable for large datasets due to performance limitations.
Using to_html()
The to_html()
function is the primary method for generating HTML output from your DataFrame.
Basic Usage
import pygwalker as pyg
import pandas as pd
df = pd.read_csv('data.csv')
html_str = pyg.to_html(df)
Function Parameters
Parameter | Type | Default | Description |
---|---|---|---|
dataset | DataFrame | - | The input DataFrame. See Dataset Of Walker for more details. |
gid | Union[int, str] | None | ID for the GraphicWalker container div. Format: 'gwalker-{gid}'. Auto-generated if None. |
field_specs | Optional[Dict[str, FieldSpec]] | None | Field specifications. Automatically inferred from dataset if not specified. |
theme_key | Literal['vega', 'g2'] | 'g2' | Theme type for GraphicWalker. |
appearance | Literal['media', 'light', 'dark'] | 'media' | Theme setting. 'media' auto-detects the OS theme. |
spec | str | "" | Chart configuration data. Can be a configuration ID, JSON, or remote file URL. |
default_tab | Literal["data", "vis"] | "vis" | Default tab to show when the UI loads. |
**kwargs | Any | - | Additional keyword arguments. |
Examples
Exporting to an HTML File
You can save the generated HTML to a file for later use or sharing:
import pandas as pd
import pygwalker as pyg
df = pd.read_csv('data.csv')
with open("pygwalker_demo.html", "w", encoding="utf-8") as f:
f.write(pyg.to_html(df))
Using PyGWalker with Shiny
PyGWalker can be integrated into Shiny applications. For a detailed guide and example, refer to our Shiny integration tutorial.
Best Practices
- Performance Considerations: Be mindful of the dataset size when using the HTML API, as it processes data on the client-side.
- Customization: Utilize the
field_specs
parameter to fine-tune how your data is interpreted and displayed. - Theming: Experiment with different
theme_key
andappearance
settings to match your application's look and feel. - Integration: When integrating with web frameworks like Shiny, ensure you handle the HTML output appropriately within your application's structure.
For more advanced usage and integration examples, please refer to the PyGWalker documentation.