Hi all !!
I am trying the last release of bokeh 2.3. As explained in github tracking PR of the datamodel, I am trying to use the tags to have sincronized a variable in js and python simultaneously from the JS side. I tried the example in examples/plotting/file/data_model.py but the tags appears empty in JS console.
I am using bokeh in windows with chrome 88.0.4324.182. The same behavior appears in firefox.
The code is the following
import numpy as np
from bokeh.core.properties import Float
from bokeh.io import save
from bokeh.layouts import column
from bokeh.model import DataModel
from bokeh.models import ColumnDataSource, CustomJS
from bokeh.plotting import figure, curdoc
class Params(DataModel):
amp = Float(default=0.1, help="Amplitude")
freq = Float(default=0.1, help="Frequency")
phase = Float(default=0, help="Phase")
offset = Float(default=-5, help="Offset")
params = Params(amp=2, freq=3, phase=0.4, offset=1)
A = params.amp
k = params.freq
phi = params.phase
B = params.offset
x = np.linspace(0, 10, 100)
y = A*np.sin(k*x + phi) + B
source = ColumnDataSource(data=dict(x=x, y=y))
plot = figure(tags=[params],y_range=(-10, 10), title="Data models example")
plot.line("x", "y", source=source, line_width=3, line_alpha=0.6)
callback = CustomJS(args=dict(source=source, params=params), code="""
const data = source.data
const A = params.amp
const k = params.freq
const phi = params.phase
const B = params.offset
const {x, y} = data
for (let i = 0; i < x.length; i++) {
y[i] = A*Math.sin(k*x[i] + phi) + B
}
source.change.emit()
""")
params.js_on_change("amp", callback)
params.js_on_change("freq", callback)
params.js_on_change("phase", callback)
params.js_on_change("offset", callback)
curdoc().add_root(column(plot))
thanks for all your work,
Best regards,
Néstor