Skip to content

edsteva.viz.utils

save_html

save_html(obj: alt.Chart, filename: str)

Save chart in the specified file

PARAMETER DESCRIPTION
obj

Altair chart to be saved

TYPE: alt.Chart

filename

Folder path where to save the chart in HTML format.

EXAMPLE: "my_folder/my_file.html"

TYPE: str

Source code in edsteva/viz/utils.py
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
def save_html(obj: alt.Chart, filename: str):
    """Save chart in the specified file

    Parameters
    ----------
    obj : alt.Chart
        Altair chart to be saved
    filename : str
        Folder path where to save the chart in HTML format.

        **EXAMPLE**: `"my_folder/my_file.html"`
    """
    if not isinstance(filename, Path):
        filename = Path(filename)
    Path.mkdir(filename.parent, exist_ok=True, parents=True)
    if hasattr(obj, "save"):
        obj.save(filename)
    else:
        with Path.open(filename, "w") as f:
            f.write(obj)
    logger.info("The chart has been saved in {}", filename)