Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

Saving figure with interactive elements #82

Closed
robna opened this issue Nov 27, 2020 · 5 comments
Closed

Saving figure with interactive elements #82

robna opened this issue Nov 27, 2020 · 5 comments

Comments

@robna
Copy link

robna commented Nov 27, 2020

Is it possible to export interactive features?
For testing I made a plot with tool tips on hover and saved to pdf and svg (via nodejs). The figure is saved without problems, but the tool tip functionality is lost.

@jakevdp
Copy link
Member

jakevdp commented Nov 27, 2020

You can save a figure to HTML and preserve interactive elements. I'm not aware of any way to create an interactive pdf or svg.

@robna
Copy link
Author

robna commented Nov 27, 2020

About pdf I also don't know if it would be feasible at all. Interactive svg however should be possible, as there are projects like @petercollingridge/code-for-blog or @sozi-projects/Sozi

And how exactly would I get interactivity in an html output? What I tried sofar is alt.Chart.show(name-of-my-chart) which opens the chart in a new browser window (outside of jupyter lab), but without interactivity.

@robna
Copy link
Author

robna commented Nov 27, 2020

sorry my mistake... alt.Chart.show(name-of-my-chart) wouldn't even be using altair_saver, but the main altair library, right?
I tried now:
from altair_saver import save
save(name-of-my-chart,'name-of-my-chart.html')
This exports a html file with interactivity preserved.

Do you know by any chance if someone has tried to make export of altair charts with interactivity work in formats such as svg or pdf?

@jakevdp
Copy link
Member

jakevdp commented Nov 28, 2020

No, I don't believe pdf files or svg files support interactivity in general, so there is no way to make Altair exports to those filetypes include interactivity. The only way to export interactive Altair charts is to save them to html, for example with chart.save('filename.html') and then view it in a web browser, or to save them to JSON with chart.save('filename.json') and then load it in javascript with a tool like vega-embed.

@joelostblom
Copy link
Member

Since Altair 5.2, the functionality of Altair Saver is now available in Altair via the vl-convert package. Most of the functionality has been available since 5.0, and the main addition in 5.2 was PDF export. See the docs on how to save charts for more details

We are going to archive this repo, so I'm closing all the open issues and PRs before doing so. Try out the new options for saving charts mentioned above and if you run into issues, please open an issue directly in the altair or vl-convert repo.

@joelostblom joelostblom closed this as not planned Won't fix, can't repro, duplicate, stale Mar 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants