Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lost interaction between ipywidgets when wrapped into bokeh #39

Open
Tracked by #91
epifanio opened this issue Oct 9, 2021 · 13 comments
Open
Tracked by #91

lost interaction between ipywidgets when wrapped into bokeh #39

epifanio opened this issue Oct 9, 2021 · 13 comments
Labels
bug Something isn't working

Comments

@epifanio
Copy link

epifanio commented Oct 9, 2021

When wrapping interconnected ipywidgets (e.g.: an IPyWidget.IntSlider with a ipyleaflet.Map.zoom) into an ipywidgets_bokeh, we lost the interaction between widgets.

Attempt to reproduce the issue:

from ipywidgets_bokeh import IPyWidget
import ipywidgets as widgets

from bokeh.layouts import row
from bokeh.plotting import curdoc
from ipyleaflet import Map, basemaps
from ipywidgets import jslink

m = Map(center=(46.01, 6.16), zoom=12, basemap=basemaps.Stamen.Terrain)
zoom_slider = widgets.IntSlider(description='Zoom level:', min=0, max=15, value=7)
jslink((zoom_slider, 'value'), (m, 'zoom'))

slider_wrapper = IPyWidget(widget=zoom_slider, width=600, height=400)
map_wrapper = IPyWidget(widget=m, width=600, height=400)


doc = curdoc()
doc.add_root(row(slider_wrapper, map_wrapper))

In the code above, the zoom slider should be connected with the zoom level into the ipywidgets map canvas.

@epifanio
Copy link
Author

interaction between widgets is not working - I am digging into the ipywidgets_bokeh src code but with no luck ... @philippjfr any pointer/way to better debug this issue? Thanks for any hints!

@epifanio
Copy link
Author

Cross-posting from: https://discourse.bokeh.org/t/bokeh-2-4-issue-rendering-ipywidgets/8441/2

Can't manage to get a basic example working. The IPywidgets are rendered correctly into a bokeh server app, but the linking between widgets is lost.

For the code above, see a running demo here: https://bokeh.epinux.com/ipw

Thanks for any help!

@bryevdv bryevdv added the bug Something isn't working label Dec 8, 2021
@bryevdv
Copy link
Member

bryevdv commented Dec 8, 2021

cc @mattpap @philippjfr for any comments

@epifanio
Copy link
Author

epifanio commented Mar 1, 2022

Hi, is there any plan to re-add the ability to interact between ipywidgets and bokeh - is such a core functionality no longer supported in ipywidgets_bokeh?

I've tried different combinations of versions for the software involved, one that worked is the following:

ipykernel==5.5.5
bokeh==2.3.3
ipywidgets_bokeh==1.0.2

@epifanio
Copy link
Author

epifanio commented Mar 9, 2022

@mattpap @philippjfr any hints on how can I debug this issue? is there any relevant log I can capture to help you debug this issue? perhaps by changing/adding logging statements into the src code? Thanks for any advice!

@epifanio
Copy link
Author

@mattpap @philippjfr Any pointer on how to debug? (jslink not working between "wrapped" ipywidget linked to bokeh widget ) -- Is this bug going to be addressed ?
I was developing an app that relies on this package, but since last October I had to pin my dependencies on older bokeh and ipykernel to make it work, in the hope this bug was receiving some love :-)
unfortunately, I am now hitting the need to upgrade the bokeh version due to awesome new features and lots of bug-fix :)

@ndmlny-qs ndmlny-qs mentioned this issue Apr 6, 2023
21 tasks
@epifanio
Copy link
Author

This is still an issue :(

I updated all the involved libraries to the latest stable version.:

(base) jovyan@0fec7b75a0de:~$ panel serve untitled.py 
2023-10-10 12:48:00,975 Starting Bokeh server version 3.2.2 (running on Tornado 6.3.3)
2023-10-10 12:48:00,976 User authentication hooks NOT provided (default user enabled)
2023-10-10 12:48:00,977 Bokeh app running at: http://localhost:5006/untitled
2023-10-10 12:48:00,977 Starting Bokeh server with process id: 261
2023-10-10 12:48:07,908 404 GET /static/extensions/ipywidgets_bokeh/ipywidgets_bokeh.js?v=1f4dc096d58f7d21e3875671aee6f29b120ab84218fa47db2cb53bc9eb5b4dac (172.17.0.1) 0.33ms
2023-10-10 12:48:07,989 WebSocket connection opened
2023-10-10 12:48:07,990 ServerConnection created

the js console log:

ipywidgets_bokeh.js:1     Failed to load resource: the server responded with a status of 404 (Not Found)
bokeh.min.js?v=3ca6425586de5036dc01992dd69aa61e9196dd02619557cfaeb1b3d8b77adf724be49401b1168483d165494ce57a6daa16e6f6d3660fef117d45028221f86357:183 [bokeh] setting log level to: 'info'
bokeh.min.js?v=3ca6425586de5036dc01992dd69aa61e9196dd02619557cfaeb1b3d8b77adf724be49401b1168483d165494ce57a6daa16e6f6d3660fef117d45028221f86357:226 [bokeh] Websocket connection 0 is now open
bokeh.min.js?v=3ca6425586de5036dc01992dd69aa61e9196dd02619557cfaeb1b3d8b77adf724be49401b1168483d165494ce57a6daa16e6f6d3660fef117d45028221f86357:226 Error: could not resolve type 'ipywidgets_bokeh.widget.IPyWidget', which could be due to a widget or a custom model not being registered before first usage
    at p.error (bokeh.min.js?v=3ca6425586de5036dc01992dd69aa61e9196dd02619557cfaeb1b3d8b77adf724be49401b1168483d165494ce57a6daa16e6f6d3660fef117d45028221f86357:211:4951)
    at p._resolve_type (bokeh.min.js?v=3ca6425586de5036dc01992dd69aa61e9196dd02619557cfaeb1b3d8b77adf724be49401b1168483d165494ce57a6daa16e6f6d3660fef117d45028221f86357:211:5059)
    at p._decode_object_ref (bokeh.min.js?v=3ca6425586de5036dc01992dd69aa61e9196dd02619557cfaeb1b3d8b77adf724be49401b1168483d165494ce57a6daa16e6f6d3660fef117d45028221f86357:211:4782)
    at p._decode (bokeh.min.js?v=3ca6425586de5036dc01992dd69aa61e9196dd02619557cfaeb1b3d8b77adf724be49401b1168483d165494ce57a6daa16e6f6d3660fef117d45028221f86357:211:1779)
    at bokeh.min.js?v=3ca6425586de5036dc01992dd69aa61e9196dd02619557cfaeb1b3d8b77adf724be49401b1168483d165494ce57a6daa16e6f6d3660fef117d45028221f86357:211:2249
    at f (bokeh.min.js?v=3ca6425586de5036dc01992dd69aa61e9196dd02619557cfaeb1b3d8b77adf724be49401b1168483d165494ce57a6daa16e6f6d3660fef117d45028221f86357:178:450)
    at p._decode_plain_array (bokeh.min.js?v=3ca6425586de5036dc01992dd69aa61e9196dd02619557cfaeb1b3d8b77adf724be49401b1168483d165494ce57a6daa16e6f6d3660fef117d45028221f86357:211:2237)
    at p._decode (bokeh.min.js?v=3ca6425586de5036dc01992dd69aa61e9196dd02619557cfaeb1b3d8b77adf724be49401b1168483d165494ce57a6daa16e6f6d3660fef117d45028221f86357:211:928)
    at p._decode_plain_object (bokeh.min.js?v=3ca6425586de5036dc01992dd69aa61e9196dd02619557cfaeb1b3d8b77adf724be49401b1168483d165494ce57a6daa16e6f6d3660fef117d45028221f86357:211:2340)
    at p._decode (bokeh.min.js?v=3ca6425586de5036dc01992dd69aa61e9196dd02619557cfaeb1b3d8b77adf724be49401b1168483d165494ce57a6daa16e6f6d3660fef117d45028221f86357:211:1066)
_repull_session_doc @ bokeh.min.js?v=3ca6425586de5036dc01992dd69aa61e9196dd02619557cfaeb1b3d8b77adf724be49401b1168483d165494ce57a6daa16e6f6d3660fef117d45028221f86357:226
bokeh.min.js?v=3ca6425586de5036dc01992dd69aa61e9196dd02619557cfaeb1b3d8b77adf724be49401b1168483d165494ce57a6daa16e6f6d3660fef117d45028221f86357:226 [bokeh] Failed to repull session Error: could not resolve type 'ipywidgets_bokeh.widget.IPyWidget', which could be due to a widget or a custom model not being registered before first usage
_repull_session_doc @ bokeh.min.js?v=3ca6425586de5036dc01992dd69aa61e9196dd02619557cfaeb1b3d8b77adf724be49401b1168483d165494ce57a6daa16e6f6d3660fef117d45028221f86357:226
bokeh.min.js?v=3ca6425586de5036dc01992dd69aa61e9196dd02619557cfaeb1b3d8b77adf724be49401b1168483d165494ce57a6daa16e6f6d3660fef117d45028221f86357:225 [bokeh] Failed to load Bokeh session M9GQ9U2HGrc6YH4vk8jdQzxgH0jpB4C8zdVJBl2SDGdi: Error: could not resolve type 'ipywidgets_bokeh.widget.IPyWidget', which could be due to a widget or a custom model not being registered before first usage
o.add_document_from_session @ bokeh.min.js?v=3ca6425586de5036dc01992dd69aa61e9196dd02619557cfaeb1b3d8b77adf724be49401b1168483d165494ce57a6daa16e6f6d3660fef117d45028221f86357:225
bokeh.min.js?v=3ca6425586de5036dc01992dd69aa61e9196dd02619557cfaeb1b3d8b77adf724be49401b1168483d165494ce57a6daa16e6f6d3660fef117d45028221f86357:163 Error rendering Bokeh items: Error: could not resolve type 'ipywidgets_bokeh.widget.IPyWidget', which could be due to a widget or a custom model not being registered before first usage
    at p.error (bokeh.min.js?v=3ca6425586de5036dc01992dd69aa61e9196dd02619557cfaeb1b3d8b77adf724be49401b1168483d165494ce57a6daa16e6f6d3660fef117d45028221f86357:211:4951)
    at p._resolve_type (bokeh.min.js?v=3ca6425586de5036dc01992dd69aa61e9196dd02619557cfaeb1b3d8b77adf724be49401b1168483d165494ce57a6daa16e6f6d3660fef117d45028221f86357:211:5059)
    at p._decode_object_ref (bokeh.min.js?v=3ca6425586de5036dc01992dd69aa61e9196dd02619557cfaeb1b3d8b77adf724be49401b1168483d165494ce57a6daa16e6f6d3660fef117d45028221f86357:211:4782)
    at p._decode (bokeh.min.js?v=3ca6425586de5036dc01992dd69aa61e9196dd02619557cfaeb1b3d8b77adf724be49401b1168483d165494ce57a6daa16e6f6d3660fef117d45028221f86357:211:1779)
    at bokeh.min.js?v=3ca6425586de5036dc01992dd69aa61e9196dd02619557cfaeb1b3d8b77adf724be49401b1168483d165494ce57a6daa16e6f6d3660fef117d45028221f86357:211:2249
    at f (bokeh.min.js?v=3ca6425586de5036dc01992dd69aa61e9196dd02619557cfaeb1b3d8b77adf724be49401b1168483d165494ce57a6daa16e6f6d3660fef117d45028221f86357:178:450)
    at p._decode_plain_array (bokeh.min.js?v=3ca6425586de5036dc01992dd69aa61e9196dd02619557cfaeb1b3d8b77adf724be49401b1168483d165494ce57a6daa16e6f6d3660fef117d45028221f86357:211:2237)
    at p._decode (bokeh.min.js?v=3ca6425586de5036dc01992dd69aa61e9196dd02619557cfaeb1b3d8b77adf724be49401b1168483d165494ce57a6daa16e6f6d3660fef117d45028221f86357:211:928)
    at p._decode_plain_object (bokeh.min.js?v=3ca6425586de5036dc01992dd69aa61e9196dd02619557cfaeb1b3d8b77adf724be49401b1168483d165494ce57a6daa16e6f6d3660fef117d45028221f86357:211:2340)
    at p._decode (bokeh.min.js?v=3ca6425586de5036dc01992dd69aa61e9196dd02619557cfaeb1b3d8b77adf724be49401b1168483d165494ce57a6daa16e6f6d3660fef117d45028221f86357:211:1066)
k @ bokeh.min.js?v=3ca6425586de5036dc01992dd69aa61e9196dd02619557cfaeb1b3d8b77adf724be49401b1168483d165494ce57a6daa16e6f6d3660fef117d45028221f86357:163
DevTools failed to load source map: Could not load content for chrome-extension://iidnbdjijdkbmajdffnidomddglmieko/sourceMap/detect-editors.js.map: System error: net::ERR_BLOCKED_BY_CLIENT

@bryevdv
Copy link
Member

bryevdv commented Oct 10, 2023

This is still an issue :(

There's not really anyone maintaining this at present. I expect this extension is of most interest to the panel/holoviz folks so perhaps issues on their trackers could encourage them to take up work on it.

I updated all the involved libraries to the latest stable version.:

you might try again, Bokeh 3.3 was just released and that 404 seems consistent with a "localhost' but that was just fixed. (Not enough information here to say at all for sure, though, just some speculation)

@philippjfr
Copy link
Contributor

There's not really anyone maintaining this at present. I expect this extension is of most interest to the panel/holoviz folks so perhaps issues on their trackers could encourage them to take up work on it.

Lightly maintained is probably more accurate, @mattpap and I have tried to fix the most crucial issues and put in a good amount of work to support latest releases of ipywidgets and Bokeh. Getting jslink to work is unfortunately quite difficult but I also haven't been able to dig into it very deeply yet.

@epifanio
Copy link
Author

epifanio commented Oct 11, 2023

Getting jslink to work is unfortunately quite difficult but I also haven't been able to dig into it very deeply yet.

I understand that, it is such a cool feature to be able to get the best of two great ecosystem back working together. If there is anything I can do to help debuging and test changes - I will be more than happy to spend time on this.

@philippjfr
Copy link
Contributor

That would be really great. I'm not 100% sure what it would take. We need to understand how jslinks work. As far as I can tell jslink creates a Link widget in ipywidgets which is then somehow serialized alongside the source and target widgets. When you embed the two ipywidgets components that the jslink references as separate models in Bokeh I don't know whether the source or target model contains a reference to the Link widget and how the WidgetManager on the frontend connects the two.

@epifanio
Copy link
Author

epifanio commented Oct 11, 2023

I don't know if that can help, but I have pinned the last version where this system was actually working well - I can share a docker image if helpful. A starting point .. could be changing the src code to add some debug statements .. ?

@MarcSkovMadsen
Copy link

MarcSkovMadsen commented Sep 21, 2024

I experience similar issue. .jslink does not work when widgets are layed out using bokeh/ panel components. But does work when layed out via ipywidgets.

panel=1.5.0,bokeh=3.5.2,ipywidgets-bokeh=1.6.0,ipyaladin=0.5.0

.jslink works

Here we layout via an ipywidgets Box and Layout.

from ipyaladin import Aladin
from ipywidgets import Box, Layout, widgets

cosmetic_options = {"show_projection_control": False, "show_fullscreen_control": False}

a = Aladin(layout=Layout(width="100%"), target="M 81", fov=0.3, **cosmetic_options)
b = Aladin(layout=Layout(width="100%"), survey="P/DSS2/red", **cosmetic_options)
c = Aladin(layout=Layout(width="100%"), survey="P/2MASS/color", **cosmetic_options)

# synchronize target between 3 widgets
widgets.jslink((a, "_target"), (b, "_target"))
widgets.jslink((b, "_target"), (c, "_target"))

# synchronize FoV (zoom level) between 3 widgets
widgets.jslink((a, "_fov"), (b, "_fov"))
widgets.jslink((b, "_fov"), (c, "_fov"))

items = [a, b, c]

box_layout = Layout(
    display="flex", flex_flow="row", align_items="stretch", border="solid", width="100%"
)
box = Box(children=items, layout=box_layout)


# See also https://github.com/cds-astro/ipyaladin/blob/master/examples/01_Getting_Started.ipynb
"""# 🛸 Getting Started

Displays an interactive sky view of the
[Mars Viking MDIM21 survey](https://alasky.u-strasbg.fr/Planets/Mars_Viking_MDIM21/) using \
[ipyaladin](https://github.com/cds-astro/ipyaladin) and \
[Panel](https://panel.holoviz.org/index.html).

[**More Examples**](./)
"""
import panel as pn
from ipyaladin import Aladin

pn.extension("ipywidgets", sizing_mode="stretch_width")

pn.template.FastListTemplate(
    site="",
    title="Getting Started with ipyaladin and Panel",
    sidebar=[
        pn.pane.PNG(
            "https://avatars.githubusercontent.com/u/26145382?s=200&v=4",
            link_url="https://cds.unistra.fr/",
        ),
        __doc__,
    ],
    main=[box],
    accent="#296bb5",
    main_layout=None,
).servable()
ipyaladin-jslink.mp4

.jslink not working

Here we layout via a panel Row.

from ipyaladin import Aladin
from ipywidgets import Box, Layout, widgets

cosmetic_options = {"show_projection_control": False, "show_fullscreen_control": False}

a = Aladin(layout=Layout(width="100%"), target="M 81", fov=0.3, **cosmetic_options)
b = Aladin(layout=Layout(width="100%"), survey="P/DSS2/red", **cosmetic_options)
c = Aladin(layout=Layout(width="100%"), survey="P/2MASS/color", **cosmetic_options)

# synchronize target between 3 widgets
widgets.jslink((a, "_target"), (b, "_target"))
widgets.jslink((b, "_target"), (c, "_target"))

# synchronize FoV (zoom level) between 3 widgets
widgets.jslink((a, "_fov"), (b, "_fov"))
widgets.jslink((b, "_fov"), (c, "_fov"))

# See also https://github.com/cds-astro/ipyaladin/blob/master/examples/01_Getting_Started.ipynb
"""# 🛸 Getting Started

Displays an interactive sky view of the
[Mars Viking MDIM21 survey](https://alasky.u-strasbg.fr/Planets/Mars_Viking_MDIM21/) using \
[ipyaladin](https://github.com/cds-astro/ipyaladin) and \
[Panel](https://panel.holoviz.org/index.html).

[**More Examples**](./)
"""
import panel as pn
from ipyaladin import Aladin

pn.extension("ipywidgets", sizing_mode="stretch_width")

box = pn.Row(
    pn.panel(a, margin=0),
    pn.panel(b, margin=0),
    pn.panel(c, margin=0),
    height=300,
    margin=0,
)

pn.template.FastListTemplate(
    site="",
    title="Getting Started with ipyaladin and Panel",
    sidebar=[
        pn.pane.PNG(
            "https://avatars.githubusercontent.com/u/26145382?s=200&v=4",
            link_url="https://cds.unistra.fr/",
        ),
        __doc__,
    ],
    main=[box],
    accent="#296bb5",
    main_layout=None,
).servable()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants