1

I'm assuming I'm doing something wrong as when I attempt to use Bokeh's 'autoload_static' function and place the script tag in my html file the graph is still interactive? In addition to this, the output of my script tag (by autoload static) doesn't look exactly the same as tutorial despite it being the same code...

Would really appreciate the help. I'm trying to output it as static so I can correctly convert it to pdf with pdfkit - which unfortunately doesn't work with interactive graphs.

Thanks!

Html :

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Bokeh Scatter Plots</title>

        <!-- <link rel="stylesheet" href="http://cdn.bokeh.org/bokeh/release/bokeh-0.12.7.min.css" type="text/css" /> -->
        <!-- <script type="text/javascript" src="http://cdn.bokeh.org/bokeh/release/bokeh-0.12.7.min.js"></script> -->

    </head>
    <body>


<script
    src="js-outputted-by-autoload_static"
    id="f9632bd4-873b-4c08-a4ad-c8a997873430"
    data-bokeh-model-id="bec3e18b-71d0-4d3d-9d6a-0079d8fc6082"
    data-bokeh-doc-id="b39e1b50-1e37-4062-92a8-888cc4424328"
></script>

</html>

Bokeh:

from bokeh.resources import CDN
from bokeh.plotting import figure
from bokeh.embed import autoload_static

plot = figure()
plot.circle([1,2], [3,4])

js, tag = autoload_static(plot, CDN, "js-outputted-by-autoload_static")
bigreddot
  • 33,642
  • 5
  • 69
  • 122
Hazzamataza
  • 983
  • 2
  • 12
  • 25

1 Answers1

0

autoload_static is not for generating images, it is for generating JavaScript files that can embed standard interactive Bokeh plots in web pages. The "static" part refers to the fact that these plots are not backed by a Bokeh server.

Since autoload_static still generates JavaScript to render onto an HTML canvas, I doubt it will be useful at all with pdfkit (which I assume cannot do anything with JS code).

If you want to create images (e.g. PNGs) of Bokeh plots, you should look at the Exporting Plots section of the User's Guide. With recent versions of Bokeh, you can do e.g.

from bokeh.io import export_png

export_png(plot, filename="plot.png")

to generate a PNG (which presumably is what pdfkit can handle). Some optional dependencies are required to be installed to use this functionality, the linked User's Guide has all the information.

bigreddot
  • 33,642
  • 5
  • 69
  • 122
  • Thanks for your response.I'm basically trying to put together a report html, that will then be turned into a PDF and emailed. I'm intending on doing this on a daily basis. The way I was envisaging it was the plot would be embedded into the html and then populated with the daily data -is this the wrong approach?If I'm not mistaken your suggesting the alternative is to have a script that generates the graphs, outputs as png, then the html file reads in from the directory its stored?I guess I could just overwrite te graph each time to reduce storage but feels like this has more room to go wrong? – Hazzamataza Oct 11 '17 at 20:50
  • Yes, if you ultimately need PDF output, then you can't use regular Bokeh plots, which are in fact JSON and JavaScript code to draw on a live HTML canvas in a browser. If you are generating reports on a daily basis I'd suggest creating a directory for every day, and putting all the images for each day in there to keep them separated. If you really need to delete things you can more easily delete directories than lots of files. But I wouldn't bother deleting at all unless storage is truly an issue. – bigreddot Oct 11 '17 at 21:38