selection not working in jupyter notebook and bokeh 12.15 ?

Hi,
I’m trying to do some simple selection callback with bokeh 12.15. The following example works in bokeh server (replacing of course ‘output_notebook’ and ‘show’ by ‘curdoc().add_root()’ but it does not seem to work in latest jupyter notebook 5.4.1 (nor jupyterlab)

from bokeh.plotting import figure, output_file
import numpy as np
from bokeh.models import ColumnDataSource,BoxSelectTool,LassoSelectTool
#output_file(“toolbar.html”)
from bokeh.io import output_notebook,show
output_notebook()

x = np.arange(1000)
y = np.random.normal(loc=1,scale=2,size=1000)

source = ColumnDataSource(data=dict({‘x’:x,‘y’:y}))

tools = “pan,box_zoom,lasso_select,reset”

p = figure(plot_width=400, plot_height=400,
title=None, toolbar_location=“below”,
toolbar_sticky=False,tools=tools)

c=p.circle(x=‘x’,y=‘y’,source=source)

def update(attr,old,new):
print(new.indices)
print(type(c.data_source.selected))

c.data_source.on_change(‘selected’,update)

show§
print(type(c.data_source.selected))

``

On the plot I see the change of style of selected points but the selected object of the source seems to never be instanciated.
Am I missing something or is this a bug (I saw that bokeh 12.15 introduced a new selection model…) ?

Thanks for your help.
Raphael

Hi,

Those steps you describe are not enough alone, and the code as given would not be expected to do anything. In particular, use of the .on_change method for callbacks **always** implies a running Bokeh server. It is definitely possible to embed Bokeh server apps inside notebooks, but it does require a different approach (basically making a function that defines the app by modifying a document, and passing that function to show). See this notebook for a complete example:

  https://github.com/bokeh/bokeh/blob/master/examples/howto/server_embed/notebook_embed.ipynb

Thanks,

Bryan

···

On Apr 10, 2018, at 03:57, [email protected] wrote:

Hi,
I'm trying to do some simple selection callback with bokeh 12.15. The following example works in bokeh server (replacing of course 'output_notebook' and 'show' by 'curdoc().add_root()' but it does not seem to work in latest jupyter notebook 5.4.1 (nor jupyterlab)

from bokeh.plotting import figure, output_file
import numpy as np
from bokeh.models import ColumnDataSource,BoxSelectTool,LassoSelectTool
#output_file("toolbar.html")
from bokeh.io import output_notebook,show
output_notebook()

x = np.arange(1000)
y = np.random.normal(loc=1,scale=2,size=1000)

source = ColumnDataSource(data=dict({'x':x,'y':y}))

tools = "pan,box_zoom,lasso_select,reset"

p = figure(plot_width=400, plot_height=400,
           title=None, toolbar_location="below",
           toolbar_sticky=False,tools=tools)

c=p.circle(x='x',y='y',source=source)

def update(attr,old,new):
    print(new.indices)
    print(type(c.data_source.selected))
    
c.data_source.on_change('selected',update)

show(p)
print(type(c.data_source.selected))
On the plot I see the change of style of selected points but the selected object of the source seems to never be instanciated.
Am I missing something or is this a bug (I saw that bokeh 12.15 introduced a new selection model...) ?

Thanks for your help.
Raphael

--
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/e2df1e92-f5ff-4731-8ca1-d6b126026be0%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Hi Bryan,
Thank you very much ! Indeed, until now I had always developed directly apps for bokeh serve, so I had not see these additionnals steps in the notebook. I now see these informations in the “Running Bokeh Server” part of the User Guide : if I may suggest, maybe it could be useful to put a pointer to this doc in the “Working in the notebook” section as it covers already all other cases (handles, interactors…) and it seems to me the natural place to look for running an app in the notebook. I can propose a doc PR if you think this is useful.

Thanks again,
Raphaël

···

Le mardi 10 avril 2018 17:58:44 UTC+2, Bryan Van de ven a écrit :

Hi,

Those steps you describe are not enough alone, and the code as given would not be expected to do anything. In particular, use of the .on_change method for callbacks always implies a running Bokeh server. It is definitely possible to embed Bokeh server apps inside notebooks, but it does require a different approach (basically making a function that defines the app by modifying a document, and passing that function to show). See this notebook for a complete example:

    [https://github.com/bokeh/bokeh/blob/master/examples/howto/server_embed/notebook_embed.ipynb](https://github.com/bokeh/bokeh/blob/master/examples/howto/server_embed/notebook_embed.ipynb)

Thanks,

Bryan

On Apr 10, 2018, at 03:57, [email protected] wrote:

Hi,

I’m trying to do some simple selection callback with bokeh 12.15. The following example works in bokeh server (replacing of course ‘output_notebook’ and ‘show’ by ‘curdoc().add_root()’ but it does not seem to work in latest jupyter notebook 5.4.1 (nor jupyterlab)

from bokeh.plotting import figure, output_file

import numpy as np

from bokeh.models import ColumnDataSource,BoxSelectTool,LassoSelectTool

#output_file(“toolbar.html”)

from bokeh.io import output_notebook,show

output_notebook()

x = np.arange(1000)

y = np.random.normal(loc=1,scale=2,size=1000)

source = ColumnDataSource(data=dict({‘x’:x,‘y’:y}))

tools = “pan,box_zoom,lasso_select,reset”

p = figure(plot_width=400, plot_height=400,

       title=None, toolbar_location="below",
       toolbar_sticky=False,tools=tools)

c=p.circle(x=‘x’,y=‘y’,source=source)

def update(attr,old,new):

print(new.indices)
print(type(c.data_source.selected))

c.data_source.on_change(‘selected’,update)

show§

print(type(c.data_source.selected))

On the plot I see the change of style of selected points but the selected object of the source seems to never be instanciated.

Am I missing something or is this a bug (I saw that bokeh 12.15 introduced a new selection model…) ?

Thanks for your help.

Raphael


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/e2df1e92-f5ff-4731-8ca1-d6b126026be0%40continuum.io.

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

A PR to add this would be very appreciated!

Thanks,

Bryan

···

On Apr 11, 2018, at 04:20, [email protected] wrote:

Hi Bryan,
Thank you very much ! Indeed, until now I had always developed directly apps for bokeh serve, so I had not see these additionnals steps in the notebook. I now see these informations in the “Running Bokeh Server” part of the User Guide : if I may suggest, maybe it could be useful to put a pointer to this doc in the “Working in the notebook” section as it covers already all other cases (handles, interactors…) and it seems to me the natural place to look for running an app in the notebook. I can propose a doc PR if you think this is useful.

Thanks again,
Raphaël

Le mardi 10 avril 2018 17:58:44 UTC+2, Bryan Van de ven a écrit :

Hi,

Those steps you describe are not enough alone, and the code as given would not be expected to do anything. In particular, use of the .on_change method for callbacks always implies a running Bokeh server. It is definitely possible to embed Bokeh server apps inside notebooks, but it does require a different approach (basically making a function that defines the app by modifying a document, and passing that function to show). See this notebook for a complete example:

    [https://github.com/bokeh/bokeh/blob/master/examples/howto/server_embed/notebook_embed.ipynb](https://github.com/bokeh/bokeh/blob/master/examples/howto/server_embed/notebook_embed.ipynb)

Thanks,

Bryan

On Apr 10, 2018, at 03:57, [email protected] wrote:

Hi,

I’m trying to do some simple selection callback with bokeh 12.15. The following example works in bokeh server (replacing of course ‘output_notebook’ and ‘show’ by ‘curdoc().add_root()’ but it does not seem to work in latest jupyter notebook 5.4.1 (nor jupyterlab)

from bokeh.plotting import figure, output_file

import numpy as np

from bokeh.models import ColumnDataSource,BoxSelectTool,LassoSelectTool

#output_file(“toolbar.html”)

from bokeh.io import output_notebook,show

output_notebook()

x = np.arange(1000)

y = np.random.normal(loc=1,scale=2,size=1000)

source = ColumnDataSource(data=dict({‘x’:x,‘y’:y}))

tools = “pan,box_zoom,lasso_select,reset”

p = figure(plot_width=400, plot_height=400,

       title=None, toolbar_location="below",
       toolbar_sticky=False,tools=tools)

c=p.circle(x=‘x’,y=‘y’,source=source)

def update(attr,old,new):

print(new.indices)
print(type(c.data_source.selected))

c.data_source.on_change(‘selected’,update)

show§

print(type(c.data_source.selected))

On the plot I see the change of style of selected points but the selected object of the source seems to never be instanciated.

Am I missing something or is this a bug (I saw that bokeh 12.15 introduced a new selection model…) ?

Thanks for your help.

Raphael


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/e2df1e92-f5ff-4731-8ca1-d6b126026be0%40continuum.io.

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 [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/e261426d-ec28-454f-8de9-7bd6f36c9311%40continuum.io.

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