bokeh / jupyter_bokeh

An extension for rendering Bokeh content in JupyterLab notebooks
BSD 3-Clause "New" or "Revised" License
253 stars 48 forks source link

Not listening to column patch events? #103

Closed ceball closed 4 years ago

ceball commented 4 years ago

I couldn't edit a dataframe using panel's ipywidgets comms (https://github.com/holoviz/panel/issues/1249), and think I narrowed it down to jupyter_bokeh (rather than panel or bokeh).

Here is an example of editing a DataTable that seems to work via bokeh serve but not in the notebook with jupyter_bokeh.

Behavior is as expected in bokeh serve

from bokeh.models.widgets.tables import DataTable
from bokeh.models import ColumnDataSource, TableColumn
from bokeh.io import curdoc
import pandas as pd

df = pd.DataFrame([[1,2],[3,4]],columns=['x','y'])
ds = ColumnDataSource(df)
dt = DataTable(source=ds, sortable=True, editable=True,
               columns=[TableColumn(field="x",title="x"),
                        TableColumn(field="y",title="y")])

def on_data_change(attr, old, new):
    print('on_data_change')
    print('...attr: %s'%attr)
    print('...old: %s'%old)
    print('...new: %s'%new)

ds.on_change('data', on_data_change)

curdoc().add_root(dt)

Running the above via bokeh serve and editing the bottom right value in the table to 300 results in this being printed:

on_data_change
...attr: data
...old: {'index': array([0, 1]), 'x': array([1, 3]), 'y': array([  2, 300])}
...new: {'index': array([0, 1]), 'x': array([1, 3]), 'y': array([  2, 300])}

(don't know why old and new are the same, but I get the updated value).

Unexpected behavior in jupyter lab

The above example in jupyter lab, with additional preamble

from bokeh.io import output_notebook
import bokeh.resources
output_notebook(resources=bokeh.resources.INLINE)

import jupyter_bokeh as jbk

and last line replaced with

jbk.BokehModel(dt)

results in the following entry in the jupyter lab log:

on_data_change
...attr: data
...old: None
...new: None

Screenshot from 2020-04-26 16-43-42


software version info

jupyter lab on linux, chromium 79.0.3945.130

$ conda list # abbreviated
# Name                    Version                   Build  Channel
bokeh                     2.0.1                      py_0    bokeh/label/dev
ipykernel                 5.2.0            py37h43977f1_1    conda-forge
ipython                   7.13.0           py37hc8dfbb8_2    conda-forge
ipywidgets                7.5.1                      py_0    conda-forge
jupyter_bokeh             2.0.0                      py_0    bokeh/label/dev
jupyter_client            6.1.2                      py_0    conda-forge
jupyter_core              4.6.3            py37hc8dfbb8_1    conda-forge
jupyterlab                2.1.0                      py_0    conda-forge
jupyterlab_server         1.1.0                      py_1    conda-forge
python                    3.7.6           h8356626_5_cpython    conda-forge
tornado                   6.0.4            py37h8f50634_1    conda-forge
widgetsnbextension        3.5.1                    py37_0    conda-forge
$ jupyter labextension list
JupyterLab v2.1.0
Known labextensions:
   app dir: /home/sefkw/mc3/envs/hvdev/share/jupyter/lab
        @bokeh/jupyter_bokeh v2.0.0  enabled  OK
        @jupyter-widgets/jupyterlab-manager v2.0.0  enabled  OK

(I checked with latest master jupyter_bokeh also)

mattpap commented 4 years ago

don't know why old and new are the same, but I get the updated value.

This is the behavior when values are updated in-place.

mattpap commented 4 years ago

This makes sense. Earlier I was under the impression that we spoke about ipywidgets_bokeh. There is code on the JS side that explicitly only supports model change events (from JS to Python).

philippjfr commented 4 years ago

I fixed this in https://github.com/bokeh/jupyter_bokeh/pull/102