Bokeh sliders - plot not updating

Hello,

Here is a short description, I need to vary an azimuth angle using a slider for a line.

My bokeh version is 0.12.4, the script below works but without update of my plot also :frowning:

What is wrong?

Thanks for your help.

import numpy as np

from math import *

from bokeh.layouts import row, widgetbox

from bokeh.models.callbacks import CustomJS

from bokeh.models import Slider

from bokeh.plotting import figure, output_file, show, ColumnDataSource

========================= Set up the data

Line length d=3000, Az=30

Az = 30

d = 3000

Xp1 = 3000sin(Azpi/180)

Yp1 = 3000cos(Azpi/180)

create arrays

x = np.array([-Xp1,0,Xp1])

y = np.array([-Yp1,0,Yp1])

source = ColumnDataSource(data=dict(x=x, y=y))

======================= Setting up the plot

plot = figure(y_range=(-3000,3000),plot_width=400, plot_height=400)

plot.line(‘x’,‘y’,source=source,color="#999999", line_alpha=.8)

~~~~~~~~~~~~~~~~~~ Azimuth Slider

callback = CustomJS(args=dict(source=source), code="""

var data = source.data;

var a = cb_obj.value;

x = data[‘x’]

y = data[‘y’]

for (i=-1; i<x.length;i++) {

x[i] = 3000iMath.sin(a*pi/180);

y[i] = 3000iMath.cos(a*pi/180);

}

source.trigger(‘change’);

“”")

Azimuth_slider = Slider(start=-180, end=180, value=Az, step=.1,

title=“Projection Plan Azimuth (deg)”,callback=callback)

Azimuth_slider.js_on_change(‘value’,callback)

layout = row(plot,widgetbox(Azimuth_slider))

show(layout)

Hi, when using JS callbacks, it's always a good idea to learn to use your browsers JavaScript console. That's the only place that's going to have any useful debugging information. In this case, it informs that "pi" is undefined. You need Math.PI instead:

  callback = CustomJS(args=dict(source=source), code="""
      var data = source.data;
      var a = cb_obj.value;
      x = data['x'];
      y = data['y'];

      for (i=0; i<x.length;i++) {
          x[i] = 3000*i*Math.sin(a*Math.PI/180);
          y[i] = 3000*i*Math.cos(a*Math.PI/180);
      }
      source.trigger('change');
  """)

Additionally, you are adding your callback in two ways, and should not do this. Either use :

  callback=callback

as an arg to Slider, OR

  Azimuth_slider.js_on_change('value',callback)

but not both.

Thanks,

Bryan

···

On Feb 14, 2017, at 09:11, [email protected] wrote:

Hello,

Here is a short description, I need to vary an azimuth angle using a slider for a line.
My bokeh version is 0.12.4, the script below works but without update of my plot also :frowning:

What is wrong?

Thanks for your help.

import numpy as np
from math import *

from bokeh.layouts import row, widgetbox
from bokeh.models.callbacks import CustomJS
from bokeh.models import Slider
from bokeh.plotting import figure, output_file, show, ColumnDataSource

# ========================= Set up the data
# Line length d=3000, Az=30
Az = 30
d = 3000
Xp1 = 3000*sin(Az*pi/180)
Yp1 = 3000*cos(Az*pi/180)

# create arrays
x = np.array([-Xp1,0,Xp1])
y = np.array([-Yp1,0,Yp1])

source = ColumnDataSource(data=dict(x=x, y=y))

# ======================= Setting up the plot
plot = figure(y_range=(-3000,3000),plot_width=400, plot_height=400)
plot.line('x','y',source=source,color="#999999", line_alpha=.8)

# ~~~~~~~~~~~~~~~~~~ Azimuth Slider
callback = CustomJS(args=dict(source=source), code="""
    var data = source.data;
    var a = cb_obj.value;
    x = data['x']
    y = data['y']
    for (i=-1; i<x.length;i++) {
        x[i] = 3000*i*Math.sin(a*pi/180);
        y[i] = 3000*i*Math.cos(a*pi/180);
    }
    source.trigger('change');
""")

Azimuth_slider = Slider(start=-180, end=180, value=Az, step=.1,
                    title="Projection Plan Azimuth (deg)",callback=callback)
Azimuth_slider.js_on_change('value',callback)

layout = row(plot,widgetbox(Azimuth_slider))

show(layout)

--
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/8efde00d-79f8-44ba-a4fb-6103382b2385%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.