In working on a flask website that will allow users to plot certain data, I decided to use bokeh instead of matplotlib as it seems to be built for embedding, with the ability to use dynamic data. I've scoured online examples, and the bokeh documentation. In the examples I see the command 'create_html_snippet', which is supposed to return a snippet of html that can be inserted into a template:
from bokeh.plotting import *
import numpy as np
# Define a function that will return an HTML snippet.
def build_plot():
# Set the output for our plot.
output_file('plot.html', title='Plot')
# Create some data for our plot.
x_data = np.arange(1, 101)
y_data = np.random.randint(0, 101, 100)
# Create a line plot from our data.
line(x_data, y_data)
# Create an HTML snippet of our plot.
snippet = curplot().create_html_snippet(embed_base_url='../static/js/',
embed_save_loc='./static/js')
# Return the snippet we want to place in our page.
return snippet
I'm running this code in conjunction with the main flask code below:
from flask import Flask, render_template
from plots import build_plot
app = Flask(__name__)
@app.route('/') # The base URL for the home page.
def render_plot():
plot_snippet = build_plot()
return plot_snippet
if __name__ == "__main__":
app.run(debug=True)
The "create_html_snippet" command is not found in the documentation, and my anaconda version of python (created by the same people that are developing bokeh) gives the following error:
AttributeError: 'Plot' object has no attribute 'create_html_snippet'
It seems like bokeh is going through rapid development, and I'm wondering if it is deprecated. Does anyone know the current best way to get the html snippet I'm looking for?