Save, export, and share charts¶
Save an interactive chart as an HTML file, or download a picture of the current
view. The examples below assume you have already created a chart; see
Getting started for a complete first example.
Save an interactive chart¶
chart.save("chart.html")
Open the file in a browser or share it with someone else. They do not need Python to zoom, hover, or use interactions defined in the chart.
The file does not include a running Python session. Code that responds to selections in Python needs a live connection.
For HTML as a string rather than a file, use chart.to_html().
Use it without internet access¶
By default, the HTML file downloads GenomeSpy’s display code when opened. Include that code in the file instead:
chart.save("chart.html", inline=True)
The file is larger, but no download is needed for the display code. Data
supplied directly to the chart is included too. Data loaded from URLs still
needs network access; inline=True does not download those datasets.
Download an image¶
Hover over the chart, or give it keyboard focus, to reveal its buttons. Choose PNG for a raster image or SVG for a vector image. These capture the current view, including its zoom.
Try the buttons on this chart:
Choose or hide the buttons¶
The default buttons are PNG, SVG, and Inspector. Inspector is a developer tool for examining a chart; you can hide it if you do not need it.
# Display once without controls.
chart.display(controls=False)
# Display only PNG and SVG, in this order.
chart.display(controls=["png", "svg"])
Available names are "png", "svg", "inspector", and "full-window"
(which expands the chart). Their order in the list sets their display order.
The same controls option works when keeping a notebook widget or saving HTML:
widget = chart.widget(controls=["inspector"])
chart.save("chart.html", controls=False)
Save the chart definition as JSON¶
For another tool to load the chart definition, save JSON instead of HTML:
chart.save("chart.json")
JSON stores the instructions and data references, not a displayed chart. It does not include display buttons or Python callbacks.
Inspect the specification¶
A specification is the collection of instructions GenomeSpy uses to draw the chart: its data, marks, axes, and interactions. You normally do not need to inspect it, but it can help when debugging or using the JavaScript API.
spec = chart.to_dict()
mark_definition = spec["mark"]
x_definition = spec["encoding"]["x"]
schema_url = spec["$schema"]
chart.to_dict() returns Python dictionaries and lists. For JSON text, use:
json_spec = chart.to_json()
Both methods check the chart for validity by default. Data supplied directly becomes JSON records; remote data remains a URL. The property names follow the GenomeSpy grammar.
See the API reference for serialization method options.