Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
bokeh example
# -*- coding: utf-8 -*-
import json
from bokeh.embed import json_item
from bokeh.plotting import figure
from bokeh.resources import CDN
from bokeh.sampledata.iris import flowers
from bokeh.embed import components
from bokeh.plotting import figure
from flask import Flask, render_template
app = Flask(__name__)
def get_line_graph():
# prepare some data
x = [1, 2, 3, 4, 5]
y = [6, 7, 2, 4, 5]
# 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)
# print(type(p))
return p
@app.route('/plot')
def plot():
# p = make_plot('petal_width', 'petal_length')
p = get_line_graph()
return json.dumps(json_item(p, "myplot"))
@app.route('/')
def index():
# plot = get_line_graph()
# script, div = components(plot)
return render_template('index.html', resources=CDN.render())
# 'index.html', script=script, div=div)
# return page.render(resources=CDN.render())
if __name__ == "__main__":
app.run(debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.