I think I am doing something wrong. Slider is not not visible so it is not effective.
I send the code below.
Thank you
‘’'This example demonstrates embedding a standalone Bokeh document
into a simple Flask application, with a basic HTML web form.
To view the example, run:
python simple.py
in this directory, and navigate to:
‘’’
from future import print_function
import flask
from math import sin,pi
from bokeh.models import Slider,CustomJS,ColumnDataSource
from bokeh.embed import components
from bokeh.plotting import figure
from bokeh.resources import INLINE,CDN
from bokeh.util.string import encode_utf8
from bokeh.io import output_file, show, vform
app = flask.Flask(name)
colors = {
‘Black’: ‘#000000’,
‘Red’: ‘#FF0000’,
‘Green’: ‘#00FF00’,
‘Blue’: ‘#0000FF’,
}
def getitem(obj, item, default):
if item not in obj:
return default
else:
return obj[item]
x=[x*0.01 for x in range(1000)]
y=[sin(2pi1*x) for x in x]
source = ColumnDataSource(data=dict(x=x, y=y))
callback = CustomJS(args=dict(source=source), code="""
var data = source.get(‘data’);
var f = cb_obj.get(‘value’)
x = data[‘x’]
y = data[‘y’]
for (i = 0; i < x.length; i++) {
y[i] = Math.sin(2Math.pix[i]*f)
}
source.trigger(‘change’);
“”")
slider = Slider(start=10, end=50, value=1, step=1, title=“power”, callback=callback)
@app.route("/")
def polynomial():
“”" Very simple embedding of a polynomial chart
“”"
Grab the inputs arguments from the URL
This is automated by the button
args = flask.request.args
Get all the form arguments in the url with defaults
color = colors[getitem(args, ‘color’, ‘Black’)]
_from = int(getitem(args, ‘_from’, 0))
to = int(getitem(args, ‘to’, 10))
Create a polynomial line graph
x = list(range(_from, to + 1))
fig = figure(title=“Polynomial”)
fig.line(x, [i ** 2 for i in x], color=color, line_width=2)
#fig.add_tools(slider)
Configure resources to include BokehJS inline in the document.
For more details see:
http://bokeh.pydata.org/en/latest/docs/reference/resources_embedding.html#bokeh-embed
js_resources = INLINE.render_js()
css_resources = CDN.render_css()
#ss=vform(slider)
elemanlar={‘fig’:fig,‘slider’:slider}
For more details see:
http://bokeh.pydata.org/en/latest/docs/user_guide/embedding.html#components
#script, divs = components(fig,INLINE)
script, divs = components(elemanlar)
print (divs)
html = flask.render_template(
‘embed.html’,
plot_script=script,
plot_div=divs,
js_resources=js_resources,
css_resources=css_resources,
color=color,
_from=_from,
to=to
)
return encode_utf8(html)
if name == “main”:
print(doc)
app.run(debug=True)
···
#####################################
<!doctype html>
Embed Demo{{ js_resources|indent(4)|safe }}
{{ css_resources|indent(4)|safe }}
{{ plot_script|indent(4)|safe }}
Select your settings:
Color:
Red Green Blue BlackFrom:
To:
Submit
{{ plot_div[‘fig’]|indent(4)|safe }}
{{plot_div[‘slider’]|safe}}
Demonstrates some very simple embedding into a webpage