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

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

Closed
nhirschey opened this issue Mar 15, 2021 · 4 comments · Fixed by #94
Closed

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

nhirschey opened this issue Mar 15, 2021 · 4 comments · Fixed by #94

Comments

@nhirschey
Copy link
Contributor

nhirschey commented Mar 15, 2021

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.

@kMutagene
Copy link
Member

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.

@nhirschey
Copy link
Contributor Author

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

@kMutagene
Copy link
Member

@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.

@nhirschey
Copy link
Contributor Author

@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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants