Using spinner in the example below: For some reason I can’t use spinner.values such as 1.08 or 4.07. I can only use values with exactly one digit after the decimal-separator, such as 1.1 or 4.1. - What is it I am not seeing?
from bokeh.plotting import figure, show, output_file, save
from bokeh.models import CustomJS, ColumnDataSource, Range1d
from bokeh.layouts import widgetbox, column, row
from bokeh.models.widgets import Spinner
"""Plot depending on User Input."""
x = [xi * 0.001 for xi in range(0, 1000)]
a, b, c = 1, 0, 0
y = [a*xi*xi + b*xi + c for xi in x]
source = ColumnDataSource(data=dict(x=x, y=y))
plot = figure(
title="y(x)=a x² + b x + c",
plot_width=400, plot_height=400,
x_axis_label="x",y_axis_label="y",
toolbar_location=None,
active_drag=None,
background_fill_color=None,
border_fill_color=None
)
plot.line('x', 'y', source=source, line_width=3, line_alpha=0.6)
callback = CustomJS(args=dict(source=source), code="""
var a = a.value;
var b = b.value;
var c = c.value;
console.log(" ");
console.log(" ");
console.log("a, b, c:");
console.log(a);
console.log(b);
console.log(c);
var compare = 1.001;
console.log("compare:");
console.log(compare);
var data = source.data;
var x = data['x'];
var y = data['y'];
for (var i = 0; i < x.length; i++) {
y[i] = a*x[i]*x[i] + b*x[i] + c;
}
source.change.emit();
""")
spin_a = Spinner(value=1, step=0.001, title="a:", callback=callback)
callback.args["a"] = spin_a
spin_b = Spinner(value=0, step=0.001, title="b:", callback=callback)
callback.args["b"] = spin_b
spin_c = Spinner(value=0, step=0.001, title="c:", callback=callback)
callback.args["c"] = spin_c
layout = column(row(spin_a, spin_b, spin_c, width=400), plot)
output_file("./spinner.html", title="spinner")
save(layout)
print("Done saving.")
show(layout)