Dear @LaurentRDC ,
first of all, thank you for this filter, it allowed me to include some nice plotly figures in my Master's thesis.
I really like having things that can be rebuilt on demand when some data changes etc., so this filter was really helpful.
Now I'm in the middle of preparing my defense and I thought I might try an HTML/JS slideshow instead of PDF, which would grant the ability to navigate the plots during the presentation.
My first attempts showed no errors, but no plots either, but I've been able to narrow the issue down.
Apparently, the plotly JS doesn't like being loaded deferred, at least I can only see plotly figures when I remove all defer
statements from the html file pandoc produces.
I've attached a minimal reproducer (which additionally shows that for bokeh, deferred loading of the library works flawless).
I'm not sure what would be the best option to solve this issue, perhaps making the deferred loading optional and disable it by default for plotly figures?
Here's the minimal reproducer:
---
title: pandoc-plot reproducer
...
# section foo
## plotly foo
```{.python .plotly_python format=html caption="sample plotly fig from https://plotly.com/python/line-and-scatter/"}
import plotly.graph_objects as go
import numpy as np
N = 1000
t = np.linspace(0, 10, 100)
y = np.sin(t)
fig = go.Figure(data=go.Scatter(x=t, y=y, mode='markers'))
```
## bokeh foo
```{.python .bokeh format=html caption="Move around in the plot by using your mouse. This gallery example was modified from [here](https://docs.bokeh.org/en/latest/docs/gallery/hex_tile.html)."}
import numpy as np
from bokeh.plotting import figure
from bokeh.transform import linear_cmap
from bokeh.util.hex import hexbin
np.random.seed(23)
n = 50000
x = np.random.standard_normal(n)
y = np.random.standard_normal(n)
bins = hexbin(x, y, 0.1)
p = figure(title="Interactive plotting with Bokeh", tools="wheel_zoom,pan,reset", match_aspect=True, background_fill_color='#440154', plot_width=550, plot_height=550)
p.grid.visible = False
p.hex_tile(q="q", r="r", size=0.1, line_color=None, source=bins,
fill_color=linear_cmap('counts', 'Viridis256', 0, max(bins.counts)))
```
Version numbers involved:
[julian@fedora pandoc_plot_reproducer]$ pandoc -v
pandoc 2.14.0.3
Compiled with pandoc-types 1.22, texmath 0.12.3, skylighting 0.10.5.2,
citeproc 0.4.0.1, ipynb 0.1.0.1
User data directory: /home/julian/.local/share/pandoc
Copyright (C) 2006-2021 John MacFarlane. Web: https://pandoc.org
This is free software; see the source for copying conditions. There is no
warranty, not even for merchantability or fitness for a particular purpose.
[julian@fedora pandoc_plot_reproducer]$ pandoc-plot -v
1.4.0
[julian@fedora pandoc_plot_reproducer]$ pip freeze | grep -i -e plotly -e bokeh
bokeh==2.4.2
plotly==5.6.0
How I built it:
pandoc --filter pandoc-plot test.md --standalone -o test.html
Testing:
firefox test.html
chromium-browser test.html
Attempted fix:
sed 's/defer></></g' test.html > test_no_defer.html
firefox test_no_defer.html
chromium-browser test_no_defer.html
Of course this sed
call above is perhaps prone to failure, if anyone reads this in the future and thinks this is a good workaround.
This is what I get as the baseline:
Here's the "fixed" version without deferring:
Please let me know if there is anything else I can try or any way to help.
Despite having had to learn some Haskell in the second year of university, I could never wrap my head around it, so I fear that I can't solve this directly...
Best regards
Julian