Skip to content

.Net Interactive using Svg (or other static) images? #65

Closed

Description

@nhirschey

Description

I want to use pandoc to convert a f# .ipynb notebook containing Plotly.NET figures to pdf. However, the conversion does not show any figures in the pdf output. I think that the issue is that Plotly.NET.Interactive renders them using javascript that gets ignored by pandoc.

pandoc notebook.ipynb -o notebook.html works fine and includes figures. But pandoc notebook.ipynb -o notebook.pdf does not have any figures in it.

This resolved pandoc issue (jgm/pandoc#6430) suggests that the conversion should be fine in python notebooks using plotly.io.renderers.default = "svg".

Can we allow a similar option in Plotly.NET.Interactive? Pandoc interop is useful because .net interactive does not have a way to save the file as a pdf or html file.

Workarounds

A current workaround to get pdf output is to use pandoc to convert to html, then use the browser's save as pdf feature to product a pdf.

Activity

  1. kMutagene commented on Mar 16, 2021

    @kMutagene
    Collaborator

    Wow that would definitely be useful. Could you by any chance have a look at the mimetype that the current output is set to? In the issue you linked, this seems to be the catch :

    "outputs": [
        {
         "output_type": "display_data",
         "data": {
          "image/svg+xml": "removed SVG code" // mimetype is set to svg here
         },
         "metadata": {}
        }
    

    I would guess that the current procedure leads to html, which explains why converting to html works but to a PDF does not. This issue however deeply relates to #21. The plot svg is rendered AFTER the html scaffold is inserted by a javascript function. This means #21 should also fix this issue, as we could then yield the pure svg/jpeg/whatever is of interest without the html around it.

  2. nhirschey commented on Mar 16, 2021

    @nhirschey
    ContributorAuthor

    It makes sense that #21 is limiting things here.

    On the mimetype, you are correct that it produces html. The current mimetype is here, and if you do HtmlFormatter.MimeType |> string you get "text\html".

    HtmlFormatter.MimeType)

    Here's a simple example trying to output svg (without a formatter), and it's calling javascript to produce the image. As you indicated, it would explain why pandoc works with html but not pdf:

    image

  3. kMutagene commented on Jul 12, 2021

    @kMutagene
    Collaborator

    @nhirschey I added a special section in the docs for the new Plotly.NET.ImageExport package that might fix your dotnet interactive problem as well. By using base64 encoded image tags or the raw SVG you should be able to correctly convert notebooks now.

  4. nhirschey commented on Jul 12, 2021

    @nhirschey
    ContributorAuthor

    @kMutagene thank you! This is amazing and I am incredibly excited to use both new features (regular static png + notebook static png).

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions