How to add Bokeh plots to a Pelican blogTue 13 November 2018
This is a little different from the normal brand of article I write, but it took me a while and surprisingly the solution wasn't easy to find on google.
First of all, you need to have bokeh set up on your local machine. Go ahead and generate a plot the usual way - some example code below (borrowed from the bokeh tutorial).
#example.py from bokeh.plotting import figure, output_file, show from bokeh.resources import CDN from bokeh.embed import file_html #data x = [1,2,3,4,5] y = [6,7,2,4,3] output_file("example.html") # create a new plot with a title and axis labels p = figure(title="simple line example", x_axis_label='x', y_axis_label='y') # add a line renderer with legend and line thickness p.line(x, y, legend="Temp.", line_width=2) # show the results show(p)
Now, when you run this code from the terminal, it should generate the example.html file.
$ python example.py
Go ahead and copy that html file into the content directory of your pelican project. Now, when writing a post, use restructured text (RST) rather than markdown, and add the following:
.. raw:: html :file: example.html
And voila! Here's an example: