Get user updated slider values

I am trying to get the updated slider values after the user moves the slider, but nothing I tried seems to work. Looking at other posts I tried ```slider.on_change(‘value’, update)`` but got a warning that " you can’t have js_on_change and on_change." Using the Bokeh example code

from bokeh.layouts import column
from bokeh.models import ColumnDataSource, CustomJS, Slider
from bokeh.plotting import figure, output_file, show

output_file("callback.html")

x = [x*0.005 for x in range(0, 200)]
y = x

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

plot = figure(plot_width=400, plot_height=400)
plot.line('x', 'y', source=source, line_width=3, line_alpha=0.6)

callback = CustomJS(args=dict(source=source), code="""
        var data = source.data;
        var f = cb_obj.value
        var x = data['x']
        var y = data['y']
        for (var i = 0; i < x.length; i++) {
            y[i] = Math.pow(x[i], f)
        }
        source.change.emit();
    """)

slider = Slider(start=0.1, end=4, value=1, step=.1, title="power")
slider.js_on_change('value', callback)

layout = column(slider, plot)

show(layout)

If the user moves the slider to 1.90, how do I get that slider value?

What do you mean by “get the updated slider values”? There’s only one value, and you’re already getting it in the CustomJS callback as cb_obj.value.

@p-himik The value that returns with cb_obj.value is the starting value not the updated value after the slider is moved. I am trying to use the slider as an input for further data analysis, but that only works if after the slider is moved I can get the updated value.

In 2.2.3 (and in any other version, AFAIK) it is absolutely the new value and not the old one. Here’s a screen recording after I added console.log(f) to the callback code. I’m moving the focused slider by pressing the left and right arrow keys.

I am using Bokeh 2.2.3 and using the console log function I can get the parameter updates to show, just as you demonstrated.

But how do I get the new value of the slider back into my jupyter notebook or get the callback code to give me the updated parameter.

No matter what I do
slider.value always equals 1 the start value

Sorry, I don’t use notebooks and I have no idea how they work so I can’t really help. Maybe @Bryan knows.

@p-himik No worries, I appreciate the help I am still learning a ton about Bokeh and JS from your comments.

@tpike3 are you asking about how to get the updated value of slider.value in Python code, in a notebook? You will have to embed a Bokeh server app for that, otherwise show is just one-way to create standalone HTML+JS that is not connected to any python process. Here is an example notebook for embedding Bokeh server,

Otherwise on OSX your code works as expected outside the notebook with no changes, and inside the notebook with replacing output_file with output_notebook, You’ll need to be more specific about your platform and versions.

@Bryan and @p-himik Thanks for all your help, I learned a ton about JS and Bokeh. Looking at the documentation @Bryan, I learned what I really wanted was Jupyter Interactors. I refactored my code and now the slider values serve as input to the next section.

Thanks again.