Hi Folks,
I’m trying to get the AjaxDataSource to work from an embedded template served from flask.
- A flask page serving data + bokeh static html work great:
@app.route("/data", methods=[‘POST’])
def get_x():
global x, y
x = x + 0.1
y = math.sin(x)
return flask.jsonify(x=, y=[y])
``
source = AjaxDataSource(data_url=“http://localhost:5000/data”, polling_interval=1000, mode=‘append’)
p = figure()
p.line(‘x’, ‘y’, source=source)
show(p)
``
- However, when I try to use an embedded plot from a flask page, the plot fails to render, and the server never sees any queries to the ‘/data’ url:
template = Template(’’’
Streaming Example
{{ js_resources }}
{{ css_resources }}
{{ plot_div }}
{{ plot_script }}
''')
@app.route("/")
def simple():
streaming=True
source = AjaxDataSource(data_url=“http://localhost:5000/data”,
polling_interval=1000, mode=‘append’)
fig = figure(title="Streaming Example")
fig.line( 'x', 'y', source=source)
js_resources = INLINE.render_js()
css_resources = INLINE.render_css()
script, div = components(fig, INLINE)
html = template.render(
plot_script=script,
plot_div=div,
js_resources=js_resources,
css_resources=css_resources
)
return encode_utf8(html)
``
Any thoughts that you might have would be much appreciated. Thanks in advance,
Brian
Cross-posted this on stack overflow and got an answer here:
···
On Saturday, May 7, 2016 at 8:12:14 AM UTC-4, [email protected] wrote:
Hi Folks,
I’m trying to get the AjaxDataSource to work from an embedded template served from flask.
- A flask page serving data + bokeh static html work great:
@app.route(“/data”, methods=[‘POST’])
def get_x():
global x, y
x = x + 0.1
y = math.sin(x)
return flask.jsonify(x=, y=[y])
``
source = AjaxDataSource(data_url=“http://localhost:5000/data”, polling_interval=1000, mode=‘append’)
p = figure()
p.line(‘x’, ‘y’, source=source)
show(p)
``
- However, when I try to use an embedded plot from a flask page, the plot fails to render, and the server never sees any queries to the ‘/data’ url:
template = Template(‘’'
Streaming Example
{{ js_resources }}
{{ css_resources }}
{{ plot_div }}
{{ plot_script }}
''')
@app.route(“/”)
def simple():
streaming=True
source = AjaxDataSource(data_url=“http://localhost:5000/data”,
polling_interval=1000, mode=‘append’)
fig = figure(title="Streaming Example")
fig.line( 'x', 'y', source=source)
js_resources = INLINE.render_js()
css_resources = INLINE.render_css()
script, div = components(fig, INLINE)
html = template.render(
plot_script=script,
plot_div=div,
js_resources=js_resources,
css_resources=css_resources
)
return encode_utf8(html)
``
Any thoughts that you might have would be much appreciated. Thanks in advance,
Brian