Confusion with updating a filtered data source using push_notebook

Hi all, I’m getting my feet wet with Bokeh and have been impressed by it overall. My main use case is from within a Jupyter notebook; I’ll write a report or simple dashboard as a Jupyter notebook, and often export to HTML to share with others. Bokeh’s interactive panning and zooming is extremely useful for this.

Recently I tried adding some custom interactive features, and ran into problems understanding how push_notebook is supposed to work. I’ll start by making a scatter plot based on a CDSView data source; after the plot’s been inserted into the notebook, I’ll update the filters on the CDSView object and then call push_notebook. Depending on exactly what I do, this either throws an exception, or does nothing. There’s an example below.

Why does push_notebook not see changes to the filters on a CDSView object?

Thanks for any suggestions!

In[1]:

import pandas as pd

import bokeh

from bokeh.io import output_notebook, push_notebook, save, show

from bokeh.models import CDSView, ColumnDataSource, BooleanFilter

from bokeh.plotting import figure

output_notebook()

In[2]:

data = pd.DataFrame(

{

‘x’: [0, 1, 2, 3],

‘y’: [1, 2, 1, 2],

}

)

In[3]:

fltr = BooleanFilter([True] * len(data))

In[4]:

source = ColumnDataSource(data)

view = CDSView(source=source, filters=[fltr])

In[5]:

f = figure(plot_height=300, plot_width=300)

circles = f.circle(x=‘x’, y=‘y’, source=source, view=view,)

t = show(f, notebook_handle=True)

Out[5] shows the expected scatter plot, with four points

In[6]:

t

Out[6]: <Bokeh Notebook handle for In[5]>

In[7]:

circles.view.filters[0].booleans

Out[7]: [True, True, True, True]

In[8]:

fltr.booleans[0] = False

In[9]:

circles.view.filters[0].booleans

Out[9]: [False, True, True, True]

In[10]:

push_notebook(handle=t)

This causes “ValueError: PATCH-DOC message requires at least one event”

In[11]:

fltr.booleans = [False] * len(data)

In[12]:

push_notebook(handle=t)

This does not cause an exception, but the plot in Out[5] does not change

In[13]:

f = figure(plot_height=300, plot_width=300)

circles = f.circle(x=‘x’, y=‘y’, source=source, view=view,)

t = show(f, notebook_handle=True)

This shows a new, empty plot, as expected

``

Hi,

I’m having the exact same issue, does anyone have suggestions?

Thanks!

···

Le samedi 18 novembre 2017 00:37:22 UTC+1, Daniel Grady a écrit :

Hi all, I’m getting my feet wet with Bokeh and have been impressed by it overall. My main use case is from within a Jupyter notebook; I’ll write a report or simple dashboard as a Jupyter notebook, and often export to HTML to share with others. Bokeh’s interactive panning and zooming is extremely useful for this.

Recently I tried adding some custom interactive features, and ran into problems understanding how push_notebook is supposed to work. I’ll start by making a scatter plot based on a CDSView data source; after the plot’s been inserted into the notebook, I’ll update the filters on the CDSView object and then call push_notebook. Depending on exactly what I do, this either throws an exception, or does nothing. There’s an example below.

Why does push_notebook not see changes to the filters on a CDSView object?

Thanks for any suggestions!

In[1]:

import pandas as pd

import bokeh

from bokeh.io import output_notebook, push_notebook, save, show

from bokeh.models import CDSView, ColumnDataSource, BooleanFilter

from bokeh.plotting import figure

output_notebook()

In[2]:

data = pd.DataFrame(

{

‘x’: [0, 1, 2, 3],

‘y’: [1, 2, 1, 2],

}

)

In[3]:

fltr = BooleanFilter([True] * len(data))

In[4]:

source = ColumnDataSource(data)

view = CDSView(source=source, filters=[fltr])

In[5]:

f = figure(plot_height=300, plot_width=300)

circles = f.circle(x=‘x’, y=‘y’, source=source, view=view,)

t = show(f, notebook_handle=True)

Out[5] shows the expected scatter plot, with four points

In[6]:

t

Out[6]: <Bokeh Notebook handle for In[5]>

In[7]:

circles.view.filters[0].booleans

Out[7]: [True, True, True, True]

In[8]:

fltr.booleans[0] = False

In[9]:

circles.view.filters[0].booleans

Out[9]: [False, True, True, True]

In[10]:

push_notebook(handle=t)

This causes “ValueError: PATCH-DOC message requires at least one event”

In[11]:

fltr.booleans = [False] * len(data)

In[12]:

push_notebook(handle=t)

This does not cause an exception, but the plot in Out[5] does not change

In[13]:

f = figure(plot_height=300, plot_width=300)

circles = f.circle(x=‘x’, y=‘y’, source=source, view=view,)

t = show(f, notebook_handle=True)

This shows a new, empty plot, as expected

``

I don't think changing .boolenas in place will work. I.e. this will not work:

  fltr.booleans[0] = False

Instead, you will have to set fltr.booleans to an entirely new list in order for the change to be detected:

  fltr.booleans = new_list

The subscript change works for CDS .data columns because those (and only those) are specially instrumented wrappers that are able to notice "in place" setitem changes like that.

Bryan

···

On Feb 8, 2018, at 04:28, [email protected] wrote:

Hi,

I'm having the exact same issue, does anyone have suggestions?

Thanks!

Le samedi 18 novembre 2017 00:37:22 UTC+1, Daniel Grady a écrit :
Hi all, I'm getting my feet wet with Bokeh and have been impressed by it overall. My main use case is from within a Jupyter notebook; I'll write a report or simple dashboard as a Jupyter notebook, and often export to HTML to share with others. Bokeh's interactive panning and zooming is extremely useful for this.

Recently I tried adding some custom interactive features, and ran into problems understanding how push_notebook is supposed to work. I'll start by making a scatter plot based on a CDSView data source; after the plot's been inserted into the notebook, I'll update the filters on the CDSView object and then call push_notebook. Depending on exactly what I do, this either throws an exception, or does nothing. There's an example below.

Why does push_notebook not see changes to the filters on a CDSView object?

Thanks for any suggestions!

# In[1]:

import pandas as pd

import bokeh
from bokeh.io import output_notebook, push_notebook, save, show
from bokeh.models import CDSView, ColumnDataSource, BooleanFilter
from bokeh.plotting import figure

output_notebook()

# In[2]:

data = pd.DataFrame(
    {
        'x': [0, 1, 2, 3],
        'y': [1, 2, 1, 2],
    }
)

# In[3]:

fltr = BooleanFilter([True] * len(data))

# In[4]:

source = ColumnDataSource(data)
view = CDSView(source=source, filters=[fltr])

# In[5]:

f = figure(plot_height=300, plot_width=300)

circles = f.circle(x='x', y='y', source=source, view=view,)

t = show(f, notebook_handle=True)

# Out[5] shows the expected scatter plot, with four points

# In[6]:

t

# Out[6]: <Bokeh Notebook handle for In[5]>

# In[7]:

circles.view.filters[0].booleans

# Out[7]: [True, True, True, True]

# In[8]:

fltr.booleans[0] = False

# In[9]:

circles.view.filters[0].booleans

# Out[9]: [False, True, True, True]

# In[10]:

push_notebook(handle=t)

# This causes "ValueError: PATCH-DOC message requires at least one event"

# In[11]:

fltr.booleans = [False] * len(data)

# In[12]:

push_notebook(handle=t)

# This does not cause an exception, but the plot in Out[5] does not change

# In[13]:

f = figure(plot_height=300, plot_width=300)

circles = f.circle(x='x', y='y', source=source, view=view,)

t = show(f, notebook_handle=True)

# This shows a new, empty plot, as expected

--
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/e7e99d23-43e1-4737-b55d-98a14397e402%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.