Search code examples
pdfjupyter-notebookbokehnbconvert

python nbconvert not exporting images for bokeh plots


Sorry I hope this is not too broad a question. I also communicated this to the bokeh gitter but no one has replied back.

So I have a jupyter notebook (notebook version 4.3.1) and I am using bokeh 12.5 to generate plots. I was trying to export the notebook to pdf using nbconvert, but for some reason I only get the notebook text and never any images.

I tried to use nbconvert 5.1.1 for the export, but then noticed an issue about someone having trouble exporting plots to reveal.js presentations using nbconvert 5.1.1 and bokeh. The issue is https://github.com/bokeh/bokeh/issues/4859 .

So I down revisioned to nbconvert 4.2 and still no luck.

From the notebook I am using the code:

 !jupyter nbconvert --to pdf notebook.ipynb --output $notebook.pdf

The messages indicate that the export is working. But when I open the pdf there are no pdfs.

 [NbConvertApp] Converting noteboo.ipynb to pdf
 [NbConvertApp] Writing 350653 bytes to notebook.tex
 [NbConvertApp] Building PDF
 [NbConvertApp] Running pdflatex 3 times: ['pdflatex', 'notebook.tex']
 [NbConvertApp] Running bibtex 1 time: ['bibtex', 'notebook']
 [NbConvertApp] WARNING | bibtex had problems, most likely because 
 there were no citations
 [NbConvertApp] PDF successfully created
 [NbConvertApp] Writing 208111 bytes to notebook.pdf

Has anyone else ran into this problem? I see the plots in the notebook with no problem, but for some reason cannot seem to export them no matter what I try.


Solution

  • Okay, I confirmed with the bokeh developers. Right now bokeh will only let you nbconvert to HTML and Reveal.js presentations. You cannot export to pdf or latex yet, since there is not ability to export bokeh images to svg/png. BUT, the good news is that apparently in the next release of Bokeh, v. 12.6, this svg/png feature will become available. The new version of bokeh should come out in 2 weeks or so.

    This is an excerpt from Gitter,

    @00krishna 09:39 5/24/2017 Say, am I able to export bokeh plots with nbconvert? Considering that bokeh plots are kept as html and not png, I was not sure that this is possible. Are there workarounds for this? Looks like this is not possible as of at least 2015 or 2016. If that is the case, then perhaps this needs to be more prominently indicated in the readme or something. Otherwise, people will engage in substantial development only to find out that they cannot export.

    @bryevdv 09:46 5/24/2017 nbconvert to plain HTML has always been possible, and still is (I just tested it earlier today, in fact) there are issues with Reveal.js but nothing apart from that PNG/SVG export is coming in the next release otherwise if you think there should be changes to docs, a PR is the best suggestion