Forum How do I...?

Empty output with Bokeh

nico
Prince produces a PDF file with only a blank page when the HTML source is created using Bokeh (http://bokeh.org/).

According to https://validator.w3.org/nu/#textarea, the HTML code contains no errors, just a few unimportant warnings.

The problem is probably due to Bokeh's JavaScript, but I'd like to know if there's a workaround in Prince. The Apple file preview in the Finder also shows a blank page, but all browsers seem to open it without any problem.

Here is an example to reproduce the problem:

# Install Bokeh with
# python -m pip install bokeh

import subprocess
from bokeh.io import output_file, show
from bokeh.plotting import figure

x = list(range(-10, 11, 1))
y = [xi**2 for xi in x]
plot = figure(
    width=400,
    height=400,
    title="Simple plot",
    x_axis_label="X",
    y_axis_label="Y",
)
plot.line(x, y, line_width=2)
fname = "bokeh_prince.html"
output_file(fname, mode="inline")
show(plot)
cmd = f"prince --javascript {fname}"
subprocess.run(cmd, shell=True, check=True)


And here are the errors returned by Prince:

prince : https://cdn.bokeh.org/bokeh/release/bokeh-3.3.0.min.js:163 : error : SyntaxError : unexpected token keyword("function")
prince : bokeh_prince.html:2 : error : ReferenceError : no such property : Bokeh
prince: bokeh_prince.html:4: error: ReferenceError: no such property : Bokeh


The PDF file is created but it contains only a blank page. Its size is 727 bytes.

mikeday
It looks like Bokeh is using async functions, which Prince does not yet support.