update bokeh data source in JS cacllback

Hi,
I am trying to link the source of graph3d vis example using a js callback attached to a slider.

I cannot get it working. The example in the documentation uses ‘add_periodic_callback()’ which works OK. Am I missing something?

Thanks

Aso

x = np.arange(0, 300, 10)
y = np.arange(0, 300, 10)
xx, yy = np.meshgrid(x, y)
xx = xx.ravel()
yy = yy.ravel()
t = 0
value = np.sin(xx/50 + t/10) * np.cos(yy/50 + t/10) * 50 + 50

source = ColumnDataSource(data=dict(x=xx, y=yy, z=value, color=value))
surface = Surface3d(x=“x”, y=“y”, z=“z”, color=“color”, data_source=source)

callback = CustomJS(args=dict(source=source), code="""
var f = cb_obj.value
x = source.data[‘x’]
y = source.data[‘y’]
for (i = 0; i < x.length; i++) {
z[i] = Math.sin(x[i]/50 + f/10) * Math.cos(y[i]/50 + f/10)* 50 + 50
}
console.log(f)
color = z
source.change.emit();
“”")

self.t = Slider(start=0, end=10, value=0, step=1, title=“t”, width=150)
self.t.js_on_change(‘value’, callback)

``

From your code, it does not appear you are actually updating or changing the value of source.data['z'] which is what needs to occur.

Thanks,

Bryan

···

On Mar 6, 2018, at 13:58, Aso <[email protected]> wrote:

Hi,
I am trying to link the source of graph3d vis example using a js callback attached to a slider.
I cannot get it working. The example in the documentation uses 'add_periodic_callback()' which works OK. Am I missing something?

Thanks
Aso

x = np.arange(0, 300, 10)
y = np.arange(0, 300, 10)
xx, yy = np.meshgrid(x, y)
xx = xx.ravel()
yy = yy.ravel()
t = 0
value = np.sin(xx/50 + t/10) * np.cos(yy/50 + t/10) * 50 + 50

source = ColumnDataSource(data=dict(x=xx, y=yy, z=value, color=value))
surface = Surface3d(x="x", y="y", z="z", color="color", data_source=source)

callback = CustomJS(args=dict(source=source), code="""
var f = cb_obj.value
x = source.data['x']
y = source.data['y']
for (i = 0; i < x.length; i++) {
z[i] = Math.sin(x[i]/50 + f/10) * Math.cos(y[i]/50 + f/10)* 50 + 50
}
console.log(f)
color = z
source.change.emit();
""")

self.t = Slider(start=0, end=10, value=0, step=1, title="t", width=150)
self.t.js_on_change('value', callback)

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/afbf808b-d4f1-4cc3-9d54-8566d66994ba%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.