Bokeh graphics embedded in quarto files?

Hi,

quarto is a tool for generating reports for reproducible science. Quarto (qmd) files
can include code and markdown, as well as citations and internal and external links, and can be rendered as pdf, html, and other file types. I think it’s a generalization of the Rmarkdown format popular with the Rstudio IDE.

Quarto does not seem to be able to render bokeh graphics. I suspect there needs to be some kind of hook into the bokehjs javascript, some generalization of output_notebook, to make this work, but that’s just a guess.

Matplotlib does work with quarto, but so does plotly, so it should be possible to deal with interactive graphics in some way.

Has anyone looked into this? I like the idea of quarto but don’t want to give up my beautiful bokeh graphics so for now it’s a non-starter.

Thanks!

1 Like

I was recently introduced to quarto, and would not mind seeing an MRE using quarto and Plotly (if you have the time, no worries if you don’t).

A quick look at quarto-cli/widgets.ts at main · quarto-dev/quarto-cli · GitHub shows that, in principle, you should be able to use BokehJS with quarto. The code shows how they are requesting Plotly from deno.land and scanning the cells to see if there are any Plotly objects in the notebook for rendering. You may want to create a ticket at quarto to see if the devs can implement BokehJS rendering.

Try injecting the Bokeh JavaScript in every cell that outputs a figure by adding output_notebook(hide_banner=True) before you show the figure in the notebook, to see if quarto will keep the JS around in its output. You’ll be keeping a lot of redundant code in your notebook if you have more than one figure, but it can’t hurt to try it out.

It turns out that output_notebook() works fine if you’re rendering quarto files to html. The problem is with rendering to pdf, where I guess you need some way to get an svg or png image to embed in the file.

I’m not aware of any jupyter hooks that would afford an option for automatic conversion PNG at notebook export time. But even if there were, generating PNG/SVG from Bokeh requires having selenium and webdrivers installed to drive a browser process. I just can’t really imagine a solution there that would not be incredibly fragile (and thus a support burden).

I think if you are generating PDFs from notebooks the best bet is probably to have Bokeh generate and display PNG or SVG output in a saved version of the notebook up front, and then convert that version to PDF.