widgetti / ipyvolume

3d plotting for Python in the Jupyter notebook based on IPython widgets using WebGL
MIT License
1.94k stars 234 forks source link

Bokeh-->Ipyvolume connection.. Can't get basic example working #396

Open gmerritt123 opened 2 years ago

gmerritt123 commented 2 years ago

Relevant versions

-Python 3.7.11 -Bokeh 2.4.1 -Ipyvolume 0.6a10 -bqplot 0.12.31

What I'm trying to do

Essentially replicate the example shown here: https://ipyvolume.readthedocs.io/en/latest/examples/bokeh.html

Reproducible example/code:

import numpy as np
import ipyvolume as ipv
import ipyvolume.bokeh

from bokeh.plotting import figure, save
from bokeh.models import Scatter, Slider, ColumnDataSource

np.random.seed(1)
data = np.array([np.random.random(500)*100,np.random.random(500)*100,np.random.random(500)*100])
f = ipv.figure()
s = ipv.scatter(data[0],data[1],data[2], size=5, size_selected=15,color='red',color_selected='blue',marker='sphere')

bk_f = figure(output_backend='webgl',tools=['pan','wheel_zoom','lasso_select'])
src = ColumnDataSource(data=dict(x=data[0],y=data[1]))
r = bk_f.scatter('x','y',source=src)
ipv.bokeh.link_data_source_selection_to_widget(src,s,'selected')

from bokeh.resources import CDN
from bokeh.embed import components

script, div = components((bk_f))
template_options = dict(extra_script_head=script + CDN.render_js() + CDN.render_css(),
                        body_pre="<h2>Do selections in 2d (bokeh)<h2>" + div + "<h2>And see the selection in ipyvolume<h2>")
ipv.embed.embed_html("test_embed.html",
                           [ipv.gcc(), ipv.bokeh.wmh], all_states=True,
                           template_options=template_options)

What happens

The html renders both the bokeh plot and the ipyvolume piece, but the selection link does not work. There are also a few errors thrown in the javascript console on initialization, and when I do a bokeh selection it seems that the 'indices' property it looks up for the link (I assume this is supposed to be for src.selected) but it returns undefined. These might be valuable clues for someone more knowledgeable than me. Gif:

NotWorks

Thanks for all you do!