You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
.Net Interactive using Svg (or other static) images? #65
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.
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.
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".
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:
@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.
Activity
kMutagene commentedon Mar 16, 2021
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 :
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 commentedon Mar 16, 2021
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 |> stringyou get "text\html".Plotly.NET/src/Plotly.NET.Interactive/Extension.fs
Line 16 in 1551c6d
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:
kMutagene commentedon Jul 12, 2021
@nhirschey I added a special section in the docs for the new
Plotly.NET.ImageExportpackage 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 commentedon Jul 12, 2021
@kMutagene thank you! This is amazing and I am incredibly excited to use both new features (regular static png + notebook static png).