☰Read-only archive⌕
Looking for help with Bokeh?

This is a read-only archive. Ask questions and join the conversation on GitHub.

Visit Community Support on GitHub →
Archived discussions · Captured October 28, 2026

question on example

Community Support
giuseppe_selli
giuseppe_selli

All,

I have recently started using bokeh and I wold like to do the following, I run the following code, which I have found in the example folder of the anaconda distribution.

Once the html file is displayed and I can move the slider, I would like to grab the current value where the slider is at and use it later in the code. At first, I thought to use a parser like pyquery, but as I looked at the source file of the html file, I couldn’t really figure out how to do that. Is there a way I can do that, that is, is there a simple way I can grab the value the slider sits at and feed it back to my python code ?

Thanks for any help,

Giuseppe

from bokeh.io import vform
from bokeh.models import ColumnDataSource, Slider

from bokeh.plotting import figure, output_file, show

from bokeh.models.actions import Callback

import os

import json

os.chdir(“c:\anaconda\rfpack\sipi\primitive”)

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 = Callback(args=dict(source=source), code="""

var data = source.get(‘data’);

var f = cb_obj.get(‘value’)

x = data[‘x’]

y = data[‘y’]

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

y[i] = Math.pow(x[i], f)

}

source.trigger(‘change’);

“”")

slider = Slider(start=0.1, end=4, value=1, step=.1, title=“power”, callback=callback)

layout = vform(slider, plot)

show(layout)

⌁   Link to post
Mateusz_Paprocki
Mateusz_Paprocki

Hi,

···

On Thu, Sep 10, 2015 at 12:15 AM, giuseppe selli giuseppe.selli@gmail.com wrote:

All,

I have recently started using bokeh and I wold like to do the following, I run the following code, which I have found in the example folder of the anaconda distribution.

Once the html file is displayed and I can move the slider, I would like to grab the current value where the slider is at and use it later in the code. At first, I thought to use a parser like pyquery, but as I looked at the source file of the html file, I couldn’t really figure out how to do that. Is there a way I can do that, that is, is there a simple way I can grab the value the slider sits at and feed it back to my python code ?

This isn’t going to work, because you have a static HTML file and the state of the slider is inside a web browser and never reflected back to the HTML file. What you should be doing is to use bokeh-server. This way you will be able to communicate with the web browser bidirectionally (via web sockets). You should look into glyphs/taylor_server.py example (located in the same examples/ directory), which, besides other things, shows how to react to slider changes. In this particular example slider is used to determine the degree of the approximating polynomial and the plot showing the function and it’s approximation is updated accordingly.

Another option is to use IPython notebook, but as far I can tell, it sill has to run bokeh-server behind the scenes, which isn’t very convenient. I think this kind of interactions using only an IPython kernel connected to a notebook is to be implemented in future. Other bokeh developers may prove me being wrong here and/or direct you to some discussions/documentation on the subject.

Mateusz

Thanks for any help,

Giuseppe

from bokeh.io import vform
from bokeh.models import ColumnDataSource, Slider

from bokeh.plotting import figure, output_file, show

from bokeh.models.actions import Callback

import os

import json

os.chdir(“c:\anaconda\rfpack\sipi\primitive”)

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 = Callback(args=dict(source=source), code=“”"

var data = source.get(‘data’);

var f = cb_obj.get(‘value’)

x = data[‘x’]

y = data[‘y’]

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

y[i] = Math.pow(x[i], f)

}

source.trigger(‘change’);

“”")

slider = Slider(start=0.1, end=4, value=1, step=.1, title=“power”, callback=callback)

layout = vform(slider, plot)

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 bokeh+unsubscribe@continuum.io.

To post to this group, send email to bokeh@continuum.io.

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/CAJGe8zYnat_DuF9MaSsxxQna_4-Yc4M%3Dsr%2BzOO_FGJFFfR-%2Bww%40mail.gmail.com.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

⌁   Link to post
giuseppe_selli
giuseppe_selli

Ok…thanks…that makes sense

Giuseppe

···

On Thu, Sep 10, 2015 at 7:01 AM, Mateusz Paprocki mateusz.paprocki@continuum.io wrote:

Hi,

–

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 bokeh+unsubscribe@continuum.io.

To post to this group, send email to bokeh@continuum.io.

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/CANFzp8h-kJiA-s9mkU9d9oqc%2BNTzChHCD8nNLu6uKAcZPbviWQ%40mail.gmail.com.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

On Thu, Sep 10, 2015 at 12:15 AM, giuseppe selli giuseppe.selli@gmail.com wrote:

All,

I have recently started using bokeh and I wold like to do the following, I run the following code, which I have found in the example folder of the anaconda distribution.

Once the html file is displayed and I can move the slider, I would like to grab the current value where the slider is at and use it later in the code. At first, I thought to use a parser like pyquery, but as I looked at the source file of the html file, I couldn’t really figure out how to do that. Is there a way I can do that, that is, is there a simple way I can grab the value the slider sits at and feed it back to my python code ?

This isn’t going to work, because you have a static HTML file and the state of the slider is inside a web browser and never reflected back to the HTML file. What you should be doing is to use bokeh-server. This way you will be able to communicate with the web browser bidirectionally (via web sockets). You should look into glyphs/taylor_server.py example (located in the same examples/ directory), which, besides other things, shows how to react to slider changes. In this particular example slider is used to determine the degree of the approximating polynomial and the plot showing the function and it’s approximation is updated accordingly.

Another option is to use IPython notebook, but as far I can tell, it sill has to run bokeh-server behind the scenes, which isn’t very convenient. I think this kind of interactions using only an IPython kernel connected to a notebook is to be implemented in future. Other bokeh developers may prove me being wrong here and/or direct you to some discussions/documentation on the subject.

Mateusz

Thanks for any help,

Giuseppe

from bokeh.io import vform
from bokeh.models import ColumnDataSource, Slider

from bokeh.plotting import figure, output_file, show

from bokeh.models.actions import Callback

import os

import json

os.chdir(“c:\anaconda\rfpack\sipi\primitive”)

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 = Callback(args=dict(source=source), code=“”"

var data = source.get(‘data’);

var f = cb_obj.get(‘value’)

x = data[‘x’]

y = data[‘y’]

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

y[i] = Math.pow(x[i], f)

}

source.trigger(‘change’);

“”")

slider = Slider(start=0.1, end=4, value=1, step=.1, title=“power”, callback=callback)

layout = vform(slider, plot)

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 bokeh+unsubscribe@continuum.io.

To post to this group, send email to bokeh@continuum.io.

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/CAJGe8zYnat_DuF9MaSsxxQna_4-Yc4M%3Dsr%2BzOO_FGJFFfR-%2Bww%40mail.gmail.com.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

⌁   Link to post
Damian_Avila
Damian_Avila

Another option is to use IPython notebook, but as far I can tell, it sill has to run bokeh-server behind the scenes, which isn’t very convenient. I think this kind of interactions using only an IPython kernel connected to a notebook is to be implemented in future. Other bokeh developers may prove me being wrong here and/or direct you to some discussions/documentation on the subject.

With the IPython notenook, you can run the slider and make the update on the BokehJS side without involving the bokeh server… here you have one example: https://github.com/bokeh/bokeh/blob/master/examples/plotting/notebook/interact_basic.ipynb

You will need to use interactive instead of interact to get the values from the slider…

Also, we need to mentions that if you have to make a lot of updates, the example in the notebook has some limitations… but there is some people trying to use the lower IPython machinery (comm) to avoid some of this problems… still, it is experimental for now…

···

On Thu, Sep 10, 2015 at 7:01 AM, Mateusz Paprocki mateusz.paprocki@continuum.io wrote:

Hi,

–

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 bokeh+unsubscribe@continuum.io.

To post to this group, send email to bokeh@continuum.io.

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/CANFzp8h-kJiA-s9mkU9d9oqc%2BNTzChHCD8nNLu6uKAcZPbviWQ%40mail.gmail.com.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

On Thu, Sep 10, 2015 at 12:15 AM, giuseppe selli giuseppe.selli@gmail.com wrote:

All,

I have recently started using bokeh and I wold like to do the following, I run the following code, which I have found in the example folder of the anaconda distribution.

Once the html file is displayed and I can move the slider, I would like to grab the current value where the slider is at and use it later in the code. At first, I thought to use a parser like pyquery, but as I looked at the source file of the html file, I couldn’t really figure out how to do that. Is there a way I can do that, that is, is there a simple way I can grab the value the slider sits at and feed it back to my python code ?

This isn’t going to work, because you have a static HTML file and the state of the slider is inside a web browser and never reflected back to the HTML file. What you should be doing is to use bokeh-server. This way you will be able to communicate with the web browser bidirectionally (via web sockets). You should look into glyphs/taylor_server.py example (located in the same examples/ directory), which, besides other things, shows how to react to slider changes. In this particular example slider is used to determine the degree of the approximating polynomial and the plot showing the function and it’s approximation is updated accordingly.

Another option is to use IPython notebook, but as far I can tell, it sill has to run bokeh-server behind the scenes, which isn’t very convenient. I think this kind of interactions using only an IPython kernel connected to a notebook is to be implemented in future. Other bokeh developers may prove me being wrong here and/or direct you to some discussions/documentation on the subject.

Mateusz

Thanks for any help,

Giuseppe

from bokeh.io import vform
from bokeh.models import ColumnDataSource, Slider

from bokeh.plotting import figure, output_file, show

from bokeh.models.actions import Callback

import os

import json

os.chdir(“c:\anaconda\rfpack\sipi\primitive”)

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 = Callback(args=dict(source=source), code=“”"

var data = source.get(‘data’);

var f = cb_obj.get(‘value’)

x = data[‘x’]

y = data[‘y’]

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

y[i] = Math.pow(x[i], f)

}

source.trigger(‘change’);

“”")

slider = Slider(start=0.1, end=4, value=1, step=.1, title=“power”, callback=callback)

layout = vform(slider, plot)

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 bokeh+unsubscribe@continuum.io.

To post to this group, send email to bokeh@continuum.io.

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/CAJGe8zYnat_DuF9MaSsxxQna_4-Yc4M%3Dsr%2BzOO_FGJFFfR-%2Bww%40mail.gmail.com.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

⌁   Link to post
escorciav
escorciav

Hi,

@giuseppe, were you able to capture the slider value?

I wasn’t able to capture the properties of a rectangle placed by this example. In my case, the push_notebook() method erase the rectangles instead of capturing the data. I also noticed that in the example pointed by @damian, source.data retains the value provided from ipython while in my case source.data is a dictionary with an empty list in each key. Are the values of the source erased at some point? Can we capture them from IPython?

···

On Friday, September 11, 2015 at 2:53:14 AM UTC+3, Damian Avila wrote:

Another option is to use IPython notebook, but as far I can tell, it sill has to run bokeh-server behind the scenes, which isn’t very convenient. I think this kind of interactions using only an IPython kernel connected to a notebook is to be implemented in future. Other bokeh developers may prove me being wrong here and/or direct you to some discussions/documentation on the subject.

With the IPython notenook, you can run the slider and make the update on the BokehJS side without involving the bokeh server… here you have one example: https://github.com/bokeh/bokeh/blob/master/examples/plotting/notebook/interact_basic.ipynb

You will need to use interactive instead of interact to get the values from the slider…

Also, we need to mentions that if you have to make a lot of updates, the example in the notebook has some limitations… but there is some people trying to use the lower IPython machinery (comm) to avoid some of this problems… still, it is experimental for now…

On Thu, Sep 10, 2015 at 1:41 PM giuseppe selli giusepp...@gmail.com wrote:

Ok…thanks…that makes sense

Giuseppe

On Thu, Sep 10, 2015 at 7:01 AM, Mateusz Paprocki mateusz....@continuum.io wrote:

Hi,

On Thu, Sep 10, 2015 at 12:15 AM, giuseppe selli giusepp...@gmail.com wrote:

All,

I have recently started using bokeh and I wold like to do the following, I run the following code, which I have found in the example folder of the anaconda distribution.

Once the html file is displayed and I can move the slider, I would like to grab the current value where the slider is at and use it later in the code. At first, I thought to use a parser like pyquery, but as I looked at the source file of the html file, I couldn’t really figure out how to do that. Is there a way I can do that, that is, is there a simple way I can grab the value the slider sits at and feed it back to my python code ?

This isn’t going to work, because you have a static HTML file and the state of the slider is inside a web browser and never reflected back to the HTML file. What you should be doing is to use bokeh-server. This way you will be able to communicate with the web browser bidirectionally (via web sockets). You should look into glyphs/taylor_server.py example (located in the same examples/ directory), which, besides other things, shows how to react to slider changes. In this particular example slider is used to determine the degree of the approximating polynomial and the plot showing the function and it’s approximation is updated accordingly.

Another option is to use IPython notebook, but as far I can tell, it sill has to run bokeh-server behind the scenes, which isn’t very convenient. I think this kind of interactions using only an IPython kernel connected to a notebook is to be implemented in future. Other bokeh developers may prove me being wrong here and/or direct you to some discussions/documentation on the subject.

Mateusz

Thanks for any help,

Giuseppe

from bokeh.io import vform
from bokeh.models import ColumnDataSource, Slider

from bokeh.plotting import figure, output_file, show

from bokeh.models.actions import Callback

import os

import json

os.chdir(“c:\anaconda\rfpack\sipi\primitive”)

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 = Callback(args=dict(source=source), code=“”"

var data = source.get(‘data’);

var f = cb_obj.get(‘value’)

x = data[‘x’]

y = data[‘y’]

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

y[i] = Math.pow(x[i], f)

}

source.trigger(‘change’);

“”")

slider = Slider(start=0.1, end=4, value=1, step=.1, title=“power”, callback=callback)

layout = vform(slider, plot)

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 bokeh+un...@continuum.io.

To post to this group, send email to bo...@continuum.io.

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/CAJGe8zYnat_DuF9MaSsxxQna_4-Yc4M%3Dsr%2BzOO_FGJFFfR-%2Bww%40mail.gmail.com.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

–

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 bokeh+un...@continuum.io.

To post to this group, send email to bo...@continuum.io.

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/CANFzp8h-kJiA-s9mkU9d9oqc%2BNTzChHCD8nNLu6uKAcZPbviWQ%40mail.gmail.com.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

–

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 bokeh+un...@continuum.io.

To post to this group, send email to bo...@continuum.io.

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/CAJGe8zZxNe2_ugyLiEt_yRtdC5YRjQhweCtTfcNhPEOLTv_uyA%40mail.gmail.com.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

⌁   Link to post
escorciav
escorciav

In case someone is hurry and needs a hack. I posted a gist to get interactions back in ipython.

Description (to save you clicks and time): I used a JS-callback and open an ipython-kernel to pass the variables updated by JS.

@Damian, Do you know a more elegant way to do this? Could you comment about the weakness of this hack?

···

On Thursday, October 22, 2015 at 1:30:55 AM UTC+3, esco...@gmail.com wrote:

Hi,

@giuseppe, were you able to capture the slider value?

I wasn’t able to capture the properties of a rectangle placed by this example. In my case, the push_notebook() method erase the rectangles instead of capturing the data. I also noticed that in the example pointed by @damian, source.data retains the value provided from ipython while in my case source.data is a dictionary with an empty list in each key. Are the values of the source erased at some point? Can we capture them from IPython?

On Friday, September 11, 2015 at 2:53:14 AM UTC+3, Damian Avila wrote:

Another option is to use IPython notebook, but as far I can tell, it sill has to run bokeh-server behind the scenes, which isn’t very convenient. I think this kind of interactions using only an IPython kernel connected to a notebook is to be implemented in future. Other bokeh developers may prove me being wrong here and/or direct you to some discussions/documentation on the subject.

With the IPython notenook, you can run the slider and make the update on the BokehJS side without involving the bokeh server… here you have one example: https://github.com/bokeh/bokeh/blob/master/examples/plotting/notebook/interact_basic.ipynb

You will need to use interactive instead of interact to get the values from the slider…

Also, we need to mentions that if you have to make a lot of updates, the example in the notebook has some limitations… but there is some people trying to use the lower IPython machinery (comm) to avoid some of this problems… still, it is experimental for now…

On Thu, Sep 10, 2015 at 1:41 PM giuseppe selli giusepp...@gmail.com wrote:

Ok…thanks…that makes sense

Giuseppe

On Thu, Sep 10, 2015 at 7:01 AM, Mateusz Paprocki mateusz....@continuum.io wrote:

Hi,

On Thu, Sep 10, 2015 at 12:15 AM, giuseppe selli giusepp...@gmail.com wrote:

All,

I have recently started using bokeh and I wold like to do the following, I run the following code, which I have found in the example folder of the anaconda distribution.

Once the html file is displayed and I can move the slider, I would like to grab the current value where the slider is at and use it later in the code. At first, I thought to use a parser like pyquery, but as I looked at the source file of the html file, I couldn’t really figure out how to do that. Is there a way I can do that, that is, is there a simple way I can grab the value the slider sits at and feed it back to my python code ?

This isn’t going to work, because you have a static HTML file and the state of the slider is inside a web browser and never reflected back to the HTML file. What you should be doing is to use bokeh-server. This way you will be able to communicate with the web browser bidirectionally (via web sockets). You should look into glyphs/taylor_server.py example (located in the same examples/ directory), which, besides other things, shows how to react to slider changes. In this particular example slider is used to determine the degree of the approximating polynomial and the plot showing the function and it’s approximation is updated accordingly.

Another option is to use IPython notebook, but as far I can tell, it sill has to run bokeh-server behind the scenes, which isn’t very convenient. I think this kind of interactions using only an IPython kernel connected to a notebook is to be implemented in future. Other bokeh developers may prove me being wrong here and/or direct you to some discussions/documentation on the subject.

Mateusz

Thanks for any help,

Giuseppe

from bokeh.io import vform
from bokeh.models import ColumnDataSource, Slider

from bokeh.plotting import figure, output_file, show

from bokeh.models.actions import Callback

import os

import json

os.chdir(“c:\anaconda\rfpack\sipi\primitive”)

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 = Callback(args=dict(source=source), code=“”"

var data = source.get(‘data’);

var f = cb_obj.get(‘value’)

x = data[‘x’]

y = data[‘y’]

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

y[i] = Math.pow(x[i], f)

}

source.trigger(‘change’);

“”")

slider = Slider(start=0.1, end=4, value=1, step=.1, title=“power”, callback=callback)

layout = vform(slider, plot)

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 bokeh+un...@continuum.io.

To post to this group, send email to bo...@continuum.io.

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/CAJGe8zYnat_DuF9MaSsxxQna_4-Yc4M%3Dsr%2BzOO_FGJFFfR-%2Bww%40mail.gmail.com.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

–

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 bokeh+un...@continuum.io.

To post to this group, send email to bo...@continuum.io.

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/CANFzp8h-kJiA-s9mkU9d9oqc%2BNTzChHCD8nNLu6uKAcZPbviWQ%40mail.gmail.com.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

–

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 bokeh+un...@continuum.io.

To post to this group, send email to bo...@continuum.io.

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/CAJGe8zZxNe2_ugyLiEt_yRtdC5YRjQhweCtTfcNhPEOLTv_uyA%40mail.gmail.com.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

⌁   Link to post

End of archived discussion · Replies are disabled