Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to save charts as images programmatically #21

Closed
kMutagene opened this issue Oct 30, 2019 · 9 comments · Fixed by #94
Closed

Add possibility to save charts as images programmatically #21

kMutagene opened this issue Oct 30, 2019 · 9 comments · Fixed by #94

Comments

@kMutagene
Copy link
Member

Creating images locally without having to open plots and click on the save as image button would be awesome. This however will take some work.

The only way i found to do this so far is using Orca, which is a command line utility that plotly itself uses to render images. Orca can be either installes as npm module, conda package, or deployed as a docker container. All of these add some overhead but i still think this is usefull. I will start to implement some functions to call orca functions and we will see how it goes.

@sanchez
Copy link

sanchez commented May 24, 2020

It is overkill but it would be possible to use Puppeteer-Sharp to render the page and then either inject JavaScript and take the screenshot or use Puppeteer to take the screenshot on page render finish

@kMutagene
Copy link
Member Author

On the first look, this actually seems to be less overhead than using Orca in a docker container, thanks for the tip!

@kMutagene
Copy link
Member Author

thanks again @sanchez , i had a short go at it and it instantly worked. Here is a POC gist for future reference:

https://gist.github.com/kMutagene/afadbd5b9cb8e6b0401e94338a2644e4

the rendered chart:

PuppeteerPlot

@sanchez
Copy link

sanchez commented May 25, 2020

no worries, excited to see this feature incorporated!

idk if plotly will allow you to but you might want to wait for a response from plotly to confirm that the chart has been rendered and the page is done. A dirty way would just be a fixed delay as well

@kMutagene
Copy link
Member Author

The way to go here is providing a Kaleido interface to render Plotly.NET Charts as images.

@nhirschey
Copy link
Contributor

I'd like to register my interest in this feature so that I can easily include F#-generated figures in latex documents.

@ilyalatt
Copy link

I've published a package that uses PuppeteerSharp and Chromium to render charts.
It's called Plotly.NET.PuppeteerRenderer.
The code is written in C# but it should not be a problem to use it in F#.
Here's a snippet:

var chart = Chart.Line<int, int, int, int>(
    x: new[] { 1, 2, 3 },
    y: new[] { 4, 5, 6 }
);

await using var renderer = await PlotlyRenderer.FetchBrowserAndLaunch();
var png = await renderer.Render(1024, 768, chart.ToFullScreenHtml());
await File.WriteAllBytesAsync("chart.png", png);

@kMutagene
Copy link
Member Author

@ilyalatt thanks for that!

@kMutagene
Copy link
Member Author

closed via #94. The docs for the new Plotly.NET.ImageExport package can be found here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants