Shmew / Feliz.Plotly

Fable bindings written in the Feliz-style for plotly.js.
https://shmew.github.io/Feliz.Plotly/
MIT License
54 stars 13 forks source link

Save plot to disk #14

Closed Gilotto closed 4 years ago

Gilotto commented 4 years ago

For my project I'm using Feliz and Plotly to generate nice plots for display in the GUI.

afbeelding

Now we want to save the plots to a location on the disk. We can use the 'save to png' button, but that is just 1 plot. We want to generate and save the plots to disk on one click, or even without user interaction. How can we achieve this?

I noticed a 'callback event' onBeforeExport in the code. Is this the event that is used to handle the 'save to png' button?

Shmew commented 4 years ago

Hi @Gilotto,

I just added support to programmatically download images, you can see an example here.

Unfortunately, plotly.js doesn't have a headless mode, so bulk downloading is only possible if the graphs are mounted in the DOM.

If your data is static, you could automate creating the images using something like puppeteer.

Gilotto commented 4 years ago

Hey @Shmew, thanks for your quick reply! Looks good tot me. I'll test it next week, after the holidays here.

Gilotto commented 4 years ago

Hey @Shmew,

Thanks for the inclusion of the download function!

It it possible to include the path to download the file to in the downloadImage function as a parameter? e.g. path = C:/Users/#Name/Documents

Or alternatively, can the downloadImage function return a link to the plot image?

Shmew commented 4 years ago

I can only expose what plotly.js has, so what you see is what you get with the downloadImage function unfortunately. If this is helpful I can certainly add it as well.

Gilotto commented 4 years ago

I didn't know about the toImage function. Looks like the thing I can use. Can you please expose this function too? Thanks!

Shmew commented 4 years ago

I just published 1.1.0 which adds the Plotly.toImage function. That same example above was update to show how it can be used.

Gilotto commented 4 years ago

Thanks for the update and the example. I got the toImage function working now!