What happened to ColumnDataSource.on_change()?

Hi,

I don’t seem to be able to register a server-side function to listen to changes in selection on a datasource any more. Previously you’d use:

source.on_change(‘selected’,self,‘update_filter’)

That would call the self.update_filter function with the standard (obj,attrname,old,new) args. I can’t get this function to fire any more, and just putting a logging line in that function confirms that it never fires.

I now see the ColumnDataSource.selected attribute form has changed:

used to be: a list of indices of selected rows

is now: a dict with constant keys ‘0d’,‘1d’,‘2d’.

To be honest I don’t quite understand the updated docstring on this, but if the on_change triggered I’d probably figure it out. Unfortunately it never seems to. Is this because the keys never update? Do I need to manual store the doc back using the new callback function?

Thanks,

Ross

Hi Ross,

source.on_change is still available. What have changed from 0.8.x to 0.9, like you have noticed, is the source selection. Normally we go through a deprecation cycle, but unfortunately this change didn’t follow this pattern. This is creating a considerable amount of confusion.

Back to your question, source.on_change should still work. You can check the selection_histogram example for instance. Also, this discussion may help. If not by best guess is that there is some error being raised somewhere that prevents the on_change callback from being called. Can you please provide some error stack or code example that we can see to help you?

For clarity, the new callback attribute is of no help here. It basically let’s you write JS code on the python side that will run in the browser when the selection is changed.

Thank you.

···

On Tue, May 19, 2015 at 11:38 AM, Ross Moore [email protected] wrote:

Hi,

I don’t seem to be able to register a server-side function to listen to changes in selection on a datasource any more. Previously you’d use:

source.on_change(‘selected’,self,‘update_filter’)

That would call the self.update_filter function with the standard (obj,attrname,old,new) args. I can’t get this function to fire any more, and just putting a logging line in that function confirms that it never fires.

I now see the ColumnDataSource.selected attribute form has changed:

used to be: a list of indices of selected rows

is now: a dict with constant keys ‘0d’,‘1d’,‘2d’.

To be honest I don’t quite understand the updated docstring on this, but if the on_change triggered I’d probably figure it out. Unfortunately it never seems to. Is this because the keys never update? Do I need to manual store the doc back using the new callback function?

Thanks,

Ross

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/2e1bc007-8da5-4a9a-9916-7e0b4389b74b%40continuum.io.

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

Fabio Pliger

Thanks Fabio. I think I’ve traced my trouble to different problem, possibly of my own doing. Thanks for the additional guidance on the new API.

···

On Tuesday, 19 May 2015 17:58:12 UTC+8, Fabio Pliger wrote:

Hi Ross,

source.on_change is still available. What have changed from 0.8.x to 0.9, like you have noticed, is the source selection. Normally we go through a deprecation cycle, but unfortunately this change didn’t follow this pattern. This is creating a considerable amount of confusion.

Back to your question, source.on_change should still work. You can check the selection_histogram example for instance. Also, this discussion may help. If not by best guess is that there is some error being raised somewhere that prevents the on_change callback from being called. Can you please provide some error stack or code example that we can see to help you?

For clarity, the new callback attribute is of no help here. It basically let’s you write JS code on the python side that will run in the browser when the selection is changed.

Thank you.

On Tue, May 19, 2015 at 11:38 AM, Ross Moore [email protected] wrote:

Hi,

I don’t seem to be able to register a server-side function to listen to changes in selection on a datasource any more. Previously you’d use:

source.on_change(‘selected’,self,‘update_filter’)

That would call the self.update_filter function with the standard (obj,attrname,old,new) args. I can’t get this function to fire any more, and just putting a logging line in that function confirms that it never fires.

I now see the ColumnDataSource.selected attribute form has changed:

used to be: a list of indices of selected rows

is now: a dict with constant keys ‘0d’,‘1d’,‘2d’.

To be honest I don’t quite understand the updated docstring on this, but if the on_change triggered I’d probably figure it out. Unfortunately it never seems to. Is this because the keys never update? Do I need to manual store the doc back using the new callback function?

Thanks,

Ross

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/2e1bc007-8da5-4a9a-9916-7e0b4389b74b%40continuum.io.

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


Fabio Pliger

for me call back function calling working good, but if we want to change source.selected indices nothing is changing in front end.

def callback1(attr, old, new):
    print 'qlllllllllllllllll'
    data = source.data
    selected = source.selected.copy()
    selected['1d']['indices'] = []
    data.selected = selected
    #source.stream(data)

plot.square('x', 'y', source=source, size=150, line_color='line_color', color='color')

curdoc().add_root(row(plot, width=800))
curdoc().title = "Sliders"

source.on_change('selected', callback1)
···

On Tuesday, 19 May 2015 15:28:12 UTC+5:30, Fabio Pliger wrote:

Hi Ross,

source.on_change is still available. What have changed from 0.8.x to 0.9, like you have noticed, is the source selection. Normally we go through a deprecation cycle, but unfortunately this change didn’t follow this pattern. This is creating a considerable amount of confusion.

Back to your question, source.on_change should still work. You can check the selection_histogram example for instance. Also, this discussion may help. If not by best guess is that there is some error being raised somewhere that prevents the on_change callback from being called. Can you please provide some error stack or code example that we can see to help you?

For clarity, the new callback attribute is of no help here. It basically let’s you write JS code on the python side that will run in the browser when the selection is changed.

Thank you.

On Tue, May 19, 2015 at 11:38 AM, Ross Moore [email protected] wrote:

Hi,

I don’t seem to be able to register a server-side function to listen to changes in selection on a datasource any more. Previously you’d use:

source.on_change(‘selected’,self,‘update_filter’)

That would call the self.update_filter function with the standard (obj,attrname,old,new) args. I can’t get this function to fire any more, and just putting a logging line in that function confirms that it never fires.

I now see the ColumnDataSource.selected attribute form has changed:

used to be: a list of indices of selected rows

is now: a dict with constant keys ‘0d’,‘1d’,‘2d’.

To be honest I don’t quite understand the updated docstring on this, but if the on_change triggered I’d probably figure it out. Unfortunately it never seems to. Is this because the keys never update? Do I need to manual store the doc back using the new callback function?

Thanks,

Ross

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/2e1bc007-8da5-4a9a-9916-7e0b4389b74b%40continuum.io.

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


Fabio Pliger

the following is total code

''' Present an interactive function explorer with slider widgets
'''

import logging
from bokeh.io import curdoc
from bokeh.client import push_session
from bokeh.layouts import row, widgetbox
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure, show
import numpy as np

x = [1,2,3,4,5,6, 1,2,3,4,5,6, 1,2,3,4,5,6, 1,2,3,4,5,6, 1,2,3,4,5,6, 1,2,3,4,5,6]
y = [6,6,6,6,6,6, 5,5,5,5,5,5, 4,4,4,4,4,4, 3,3,3,3,3,3, 2,2,2,2,2,2, 1,1,1,1,1,1]

color=["gold", "gold", "gold", "gold", "gold","gold", "gold","gold", "gold",
       "gold", "gold", "gold", "gold", "gold", "gold", "gold", "gold", "gold",
       "gold", "gold", "gold", "gold", "gold", "gold", "gold", "gold", "gold",
       "gold", "gold", "gold", "gold", "gold", "gold", "gold", "gold", "gold"]
line_color=["white", "white", "white", "white", "white","white", "white","white", "white",
            "white", "white", "white", "white", "white", "white", "white", "white", "white",
            "white", "white", "white", "white", "white", "white", "white", "white", "white",
            "white", "white", "white", "white", "white", "white", "white", "white", "white"]
info={'users_info':{'user1':{'selections': [], 'color': '#ff6600'},'user2': {'selections':[], 'color': '#00cc99'}},
      'selecting_user': 'user1',
      'moving_selected_indices': -1}

source = ColumnDataSource(data=dict(x=x, y=y, color=color, info=info, line_color=line_color))

# Set up plot
plot = figure(plot_width=850, plot_height=850,tools="tap", title="Tic Tac")

def callback1(attr, old, new):
    data = source.data
    selected = source.selected.copy()
    selected['1d']['indices'] = []
    data.selected = selected

plot.square('x', 'y', source=source, size=150, line_color='line_color', color='color')
curdoc().add_root(row(plot, width=800))
curdoc().title = "Sliders"
source.on_change('selected', callback1)

···

On Tuesday, 19 May 2015 15:28:12 UTC+5:30, Fabio Pliger wrote:

Hi Ross,

source.on_change is still available. What have changed from 0.8.x to 0.9, like you have noticed, is the source selection. Normally we go through a deprecation cycle, but unfortunately this change didn’t follow this pattern. This is creating a considerable amount of confusion.

Back to your question, source.on_change should still work. You can check the selection_histogram example for instance. Also, this discussion may help. If not by best guess is that there is some error being raised somewhere that prevents the on_change callback from being called. Can you please provide some error stack or code example that we can see to help you?

For clarity, the new callback attribute is of no help here. It basically let’s you write JS code on the python side that will run in the browser when the selection is changed.

Thank you.

On Tue, May 19, 2015 at 11:38 AM, Ross Moore [email protected] wrote:

Hi,

I don’t seem to be able to register a server-side function to listen to changes in selection on a datasource any more. Previously you’d use:

source.on_change(‘selected’,self,‘update_filter’)

That would call the self.update_filter function with the standard (obj,attrname,old,new) args. I can’t get this function to fire any more, and just putting a logging line in that function confirms that it never fires.

I now see the ColumnDataSource.selected attribute form has changed:

used to be: a list of indices of selected rows

is now: a dict with constant keys ‘0d’,‘1d’,‘2d’.

To be honest I don’t quite understand the updated docstring on this, but if the on_change triggered I’d probably figure it out. Unfortunately it never seems to. Is this because the keys never update? Do I need to manual store the doc back using the new callback function?

Thanks,

Ross

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/2e1bc007-8da5-4a9a-9916-7e0b4389b74b%40continuum.io.

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


Fabio Pliger

When I run your code, and put a print in the callback, I see that it runs for me.

However, I should warn you that what you are doing with "info" will be disallowed in 0.12.2 about to be released, unfortunately. Errors resulting from lax property validation on Column Data Sources has become a large support burden we cannot maintain, so we are tightening things up quite a bit. Going forward column data sources may only contain actual columns (e.g. lists, arrays) of data, and following shortly, will be validated to ensure they are all the same length as well.

There is an issue you can follow about adding "namespace" models to Bokeh:
  
  Add DataModel base class · Issue #3674 · bokeh/bokeh · GitHub

This facility would provide a "scratch space" for things like your info dict. My hope is for this to be in 0.12.3 a bit later this fall.

Thanks,

Bryan

···

On Aug 25, 2016, at 12:43 PM, [email protected] wrote:

the following is total code

''' Present an interactive function explorer with slider widgets
'''

import logging
from bokeh.io import curdoc
from bokeh.client import push_session
from bokeh.layouts import row, widgetbox
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure, show
import numpy as np

x = [1,2,3,4,5,6, 1,2,3,4,5,6, 1,2,3,4,5,6, 1,2,3,4,5,6, 1,2,3,4,5,6, 1,2,3,4,5,6]
y = [6,6,6,6,6,6, 5,5,5,5,5,5, 4,4,4,4,4,4, 3,3,3,3,3,3, 2,2,2,2,2,2, 1,1,1,1,1,1]

color=["gold", "gold", "gold", "gold", "gold","gold", "gold","gold", "gold",
       "gold", "gold", "gold", "gold", "gold", "gold", "gold", "gold", "gold",
       "gold", "gold", "gold", "gold", "gold", "gold", "gold", "gold", "gold",
       "gold", "gold", "gold", "gold", "gold", "gold", "gold", "gold", "gold"]
line_color=["white", "white", "white", "white", "white","white", "white","white", "white",
            "white", "white", "white", "white", "white", "white", "white", "white", "white",
            "white", "white", "white", "white", "white", "white", "white", "white", "white",
            "white", "white", "white", "white", "white", "white", "white", "white", "white"]
info={'users_info':{'user1':{'selections': , 'color': '#ff6600'},'user2': {'selections':, 'color': '#00cc99'}},
      'selecting_user': 'user1',
      'moving_selected_indices': -1}

source = ColumnDataSource(data=dict(x=x, y=y, color=color, info=info, line_color=line_color))

# Set up plot
plot = figure(plot_width=850, plot_height=850,tools="tap", title="Tic Tac")

def callback1(attr, old, new):
    data = source.data
    selected = source.selected.copy()
    selected['1d']['indices'] =
    data.selected = selected

plot.square('x', 'y', source=source, size=150, line_color='line_color', color='color')
curdoc().add_root(row(plot, width=800))
curdoc().title = "Sliders"
source.on_change('selected', callback1)

On Tuesday, 19 May 2015 15:28:12 UTC+5:30, Fabio Pliger wrote:
Hi Ross,

source.on_change is still available. What have changed from 0.8.x to 0.9, like you have noticed, is the source selection. Normally we go through a deprecation cycle, but unfortunately this change didn't follow this pattern. This is creating a considerable amount of confusion.

Back to your question, source.on_change should still work. You can check the selection_histogram example for instance. Also, this discussion may help. If not by best guess is that there is some error being raised somewhere that prevents the on_change callback from being called. Can you please provide some error stack or code example that we can see to help you?

For clarity, the new callback attribute is of no help here. It basically let's you write JS code on the python side that will run in the browser when the selection is changed.

Thank you.

On Tue, May 19, 2015 at 11:38 AM, Ross Moore <[email protected]> wrote:
Hi,

I don't seem to be able to register a server-side function to listen to changes in selection on a datasource any more. Previously you'd use:
source.on_change('selected',self,'update_filter')

That would call the self.update_filter function with the standard (obj,attrname,old,new) args. I can't get this function to fire any more, and just putting a logging line in that function confirms that it never fires.

I now see the ColumnDataSource.selected attribute form has changed:
used to be: a list of indices of selected rows
is now: a dict with constant keys '0d','1d','2d'.

To be honest I don't quite understand the updated docstring on this, but if the on_change triggered I'd probably figure it out. Unfortunately it never seems to. Is this because the keys never update? Do I need to manual store the doc back using the new callback function?

Thanks,
Ross

--
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/2e1bc007-8da5-4a9a-9916-7e0b4389b74b%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

--
Fabio Pliger

--
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/fc4571aa-5740-472d-bbf1-c6c1640f0b97%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.