Kanaries / pygwalker

PyGWalker: Turn your pandas dataframe into an interactive UI for visual analysis
https://kanaries.net/pygwalker
Apache License 2.0
11.08k stars 570 forks source link

feat: add new html apis #480

Closed longxiaofei closed 5 months ago

longxiaofei commented 5 months ago

to_table_html

def to_table_html(
    df: DataFrame,
    *,
    theme_key: Literal['vega', 'g2'] = 'g2',
    dark: Literal['media', 'light', 'dark'] = 'media',
    **kwargs
) -> str:
    """
    Generate embeddable HTML code of Graphic Walker with data of `df`.

    Args:
        - df (pl.DataFrame | pd.DataFrame, optional): dataframe.

    Kargs:
        - theme_key ('vega' | 'g2'): theme type.
        - dark ('media' | 'light' | 'dark'): 'media': auto detect OS theme.
    """
    pass
from pygwalker.api.html import to_table_html

with open("pyg_table.html", "w") as f:
    f.write(to_table_html(df))

to_render_html

def to_render_html(
    df: DataFrame,
    spec: str,
    *,
    theme_key: Literal['vega', 'g2'] = 'g2',
    dark: Literal['media', 'light', 'dark'] = 'media',
    **kwargs
) -> str:
    """
    Args:
        - df (pl.DataFrame | pd.DataFrame, optional): dataframe.
        - spec (str): chart config data. config id, json, remote file url

    Kargs:
        - theme_key ('vega' | 'g2'): theme type.
        - dark ('media' | 'light' | 'dark'): 'media': auto detect OS theme.
    """
    pass
from pygwalker.api.html import to_table_html

with open("pyg_render.html", "w") as f:
    f.write(to_render_html(df))