bokeh / jupyter_bokeh

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

module 'jupyter_bokeh' has no attribute 'BokehModel' #137

Closed sdbbs closed 2 years ago

sdbbs commented 2 years ago

Hi all,

Thanks for a great library.

All I want to do is, to put a bokeh plot inside ipywidgets (HBox, VBox) in Jupyter notebook.

So, I installed jupyter_bokeh, and I'm trying to follow the (as of now latest) https://github.com/bokeh/jupyter_bokeh/blob/e3ef4c9/examples/jupyter_widgets.ipynb :

...
import jupyter_bokeh as jbk
...
jbk.BokehModel(p)

However, I'm doing this quick test:

(notebook) jupyter@myserver:/home/jupyter/Jupyter$ python3
Python 3.8.10 (default, Jun  2 2021, 10:49:15)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import jupyter_bokeh as jbk
>>> jbk.__version__
'3.0.2'
>>> jbk.BokehModel(None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'jupyter_bokeh' has no attribute 'BokehModel'

Looking through the source, I believe this should be:

>>> import jupyter_bokeh as jbk
>>> import jupyter_bokeh.widgets as jbkw
>>> jbkw.BokehModel(None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user11436/brothersdev.dk/Jupyter/notebook/lib/python3.8/site-packages/jupyter_bokeh/widgets.py", line 69, in __init__
    assert isinstance(model, LayoutDOM)
AssertionError

Please update your documentation - and thanks again!

bryevdv commented 2 years ago

@philippjfr it looks like you removed the BokehModel import from __init__.py in 8f21a150e21ea88747e0e0c994299f1a1bb5e4d4 Was that intentional? (Should the import be restored, or should the notebook be updated?)

philippjfr commented 2 years ago

That was indeed intentional but I should have updated the docs. The reason why I removed the import is that importing the module will register the Bokeh extension, which means you may be pointlessly loading an extra JS bundle.

philippjfr commented 2 years ago

Actually not sure that even makes sense and I'm just confused. I think the import should be restored after all.

bryevdv commented 2 years ago

@sdbbs would you like to submit the small PR to restore the import to __init__.py We are in the middle of a release of the main project at the moment so it would in fact be a big assistance.

sdbbs commented 2 years ago

Hi all,

Thanks for the feedback!

would you like to submit the small PR to restore the import to init.py

I wouldn't mind, but just to make sure I am not misunderstood, I do not mind the import being where it is; I'm a first-time user, so it's not like I'm used to anything.

All I think is needed, is that jupyter_widgets.ipynb is updated with the correct import, since this file serves as the documentation at the moment - so I made this PR:

https://github.com/bokeh/jupyter_bokeh/pull/138

Does that look OK to you all?

bryevdv commented 2 years ago

@sdbbs the import was moved in error, it would be better to restore it and leave the notebook as it has always been, if for no other reason than to reduce the potential future support burden of an unplanned breaking change.

sdbbs commented 2 years ago

Hi @bryevdv

the import was moved in error, it would be better to restore it and leave the notebook as it has always been

Ah, OK, I see - thanks!

I'm not sure I have the entire development ecosystem, but I looked into 8f21a15, and as far as I could see, it was only about restoring a single line of code; this is the way I tested on my headless server:

$ git clone https://sdbbs@github.com/sdbbs/jupyter_bokeh.git jupyter_bokeh_git
...
$ cd jupyter_bokeh_git/
jupyter_bokeh_git$ git checkout -b sdbbs-restore-import
jupyter_bokeh_git$ nano jupyter_bokeh/__init__.py  # edit the change here
jupyter_bokeh_git$ ln -s ../package.json jupyter_bokeh/
jupyter_bokeh_git$ mkdir jupyter_bokeh/labextension
jupyter_bokeh_git$ ln -s ../../package.json jupyter_bokeh/ labextension/
jupyter_bokeh_git$ python3
Python 3.8.10 (default, Jun  2 2021, 10:49:15)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import jupyter_bokeh as jbk
>>> jbk.BokehModel(None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "~/Jupyter/jupyter_bokeh_git/jupyter_bokeh/widgets.py", line 69, in __init__
    assert isinstance(model, LayoutDOM)
AssertionError

Since now I got AssertionError complaining that the model is not isinstance -- instead of the previous AttributeError: module 'jupyter_bokeh' has no attribute 'BokehModel' -- I'm assuming it is fine?

EDIT: and the pull request is:

https://github.com/bokeh/jupyter_bokeh/pull/139

Hope this works out ...

bryevdv commented 2 years ago

Closing since the PR was merged