Skip to content

Add possibility to save charts as images programmatically #21

Closed

Description

@kMutagene

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.

Activity

  1. self-assigned this
    on Oct 30, 2019
  2. sanchez commented on May 24, 2020

    @sanchez

    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

  3. kMutagene commented on May 25, 2020

    @kMutagene
    CollaboratorAuthor

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

  4. kMutagene commented on May 25, 2020

    @kMutagene
    CollaboratorAuthor

    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

  5. sanchez commented on May 25, 2020

    @sanchez

    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

  6. added this to the 2.0 milestone on Jun 15, 2020
  7. kMutagene commented on Sep 14, 2020

    @kMutagene
    CollaboratorAuthor

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

  8. nhirschey commented on Feb 23, 2021

    @nhirschey
    Contributor

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

  9. ilyalatt commented on Apr 17, 2021

    @ilyalatt

    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);
  10. kMutagene commented on Apr 20, 2021

    @kMutagene
    CollaboratorAuthor

    @ilyalatt thanks for that!

  11. kMutagene commented on Jul 12, 2021

    @kMutagene
    CollaboratorAuthor

    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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions