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

How to display ipyvolume figures in a bokeh server app? #182

Closed
GenevieveBuckley opened this issue Sep 27, 2018 · 12 comments
Closed

How to display ipyvolume figures in a bokeh server app? #182

GenevieveBuckley opened this issue Sep 27, 2018 · 12 comments

Comments

@GenevieveBuckley
Copy link
Contributor

I'd like to know how to display an ipyvolume figure in a bokeh server app.

Ideally I want to run a bokeh server app that shows users a bokeh scatterplot; and then when any of the points are clicked a new ipyvolume rendering (based on data related to the scatter point) is displayed or updated beside it.

Thanks to the ipyvolume documentation, I know how to embed linked bokeh and ipyvolume plots to a standalone html page. I'm not sure how to extend this idea to the bokeh server, though.

I've uploaded a minimal example you can run here.

Attempting to pass an ipyvolume figure, or the ipyvolume current container into a bokeh layout:

my_layout = layout([[fig]])
my_layout = layout([[ipv.gcf()]])
my_layout = layout([[ipv.gcc()]])

produces this error: ValueError: Only LayoutDOM items can be inserted into a layout.

Attempting to wrap the ipyvolume current container inside an ipywidgets or bokeh widgetbox:

my_layout = layout([[ipywidgets.HBox(ipv.gcc())]])
my_layout = layout([[bokeh.layouts.WidgetBox(ipv.gcc())]])

produces this error: ValueError: expected an element of List(Instance(Widget)), got seq with invalid items [VBox...

How should I be doing this instead?

@GenevieveBuckley
Copy link
Contributor Author

I should add: one possibly hacky workaround would be for us to run a python callback from bokeh that generates and saves a html embedding of a single ipyvolume figure, and then opening that in a separate tab using a bokeh OpenURL callback.

But I deeply dislike this idea, because:

  1. It's really hacky, and not in a good way.
  2. It makes it harder to explore the data.
  3. Worst of all, we lose any non-javascript widget functionality for the ipyvolume figure. This means no switching transfer functions on a multivolume rendering, since my solution for that currently involves a python callback.

@maartenbreddels
Copy link
Collaborator

I don't think ipywidgets can live in the bokeh server, since they need to communicate to the kernel over a Comm object (via websocket).
There is a new project: https://github.com/QuantStack/voila
Which executes your notebook and just shows the output, let me know if that helps you.
Also, take a look at bqplot https://github.com/bloomberg/bqplot/ for 2d viz, it might be easier to hook up to ipyvolume, since it's also build on top of ipywidgets.

@jni
Copy link

jni commented Sep 28, 2018

@maartenbreddels (👋)

I don't think ipywidgets can live in the bokeh server, since they need to communicate to the kernel over a Comm object (via websocket).

Can you elaborate on this? Sorry, I'm a js and server noob here, but it seems that there's ways to make Bokeh servers and Jupyter notebooks play well together (e.g. this example), which to me suggests that ipywidgets and Bokeh servers should be able to interact? ie maybe the Bokeh server needs to live in a Jupyter kernel, but that seems doable?

@GenevieveBuckley
Copy link
Contributor Author

Thank you very much for your reply, I've been thinking about this.
I'm not sure either of those suggestions are quite going to work out for us, but I will try and focus on:

  1. Figuring out if I can turn python callbacks into client-side callbacks with javascript (eg: for the colorpicker widget at [WIP] FEATURE: Multivolume rendering for multi-dimensional data #186)
  2. @jni's idea to try and make the whole bokeh server live in a Jupyter kernel.

@maartenbreddels
Copy link
Collaborator

@maartenbreddels (👋)

scipy 2018 right? :) 👋

Can you elaborate on this? Sorry, I'm a js and server noob here, but it seems that there's ways to make Bokeh servers and Jupyter notebooks play well together (e.g. this example), which to me suggests that ipywidgets and Bokeh servers should be able to interact? ie maybe the Bokeh server needs to live in a Jupyter kernel, but that seems doable?

True, I think if it lives in a jupyter kernel it should work. For standalone, I doubt it will work.

I'm not sure either of those suggestions are quite going to work out for us

Why would voila not work?

@jni
Copy link

jni commented Oct 1, 2018

scipy 2018

Yes! Great talk! =)

Why would voila not work?

Ah! I'd misunderstood what it was. It just might! The downside is that I don't want our app code to live in an ipynb file LOL. But we might be able to take little bits and pieces from voila to execute our Bokeh server as if it was running in a notebook.

As to bq, we already have a pretty developed app in Bokeh that I'm not quite ready to abandon, as it works great for 2D images. Let's see how far we can go. =)

@maartenbreddels
Copy link
Collaborator

Otherwise you can also try https://github.com/pbugnion/ipywidgets_server
I think voila and ipywidgets server might merge into 1 in the future, I hope so at least.

@maartenbreddels
Copy link
Collaborator

Yes! Great talk! =)

thx :)

I've been doing some work with bqplot for Image:
bqplot/bqplot#630
It is using WebGL for Image drawing, meaning that changing the colormap or its properties will only trigger a redraw, not sending all the data. If it is useful for you, or if you need any features, now would be the moment to request :)

and for large amounts of data:
bqplot/bqplot#661
It's not yet merged though,

@jni
Copy link

jni commented Oct 1, 2018

WOW, that megascatter lasso selection is 🔥 🔥 🔥! 😲

Well, what we are doing is to link scatter selection (not so many points ;) with (multi)image display (each point is an image). So long as your design doesn't forbid that, we will definitely be keeping an eye on this!

@rchossein
Copy link

@GenevieveBuckley did you end up solving it? Now it's possible to have the whole Bokeh server live inside Jupyter Kernel. Did you find a way to make Bokeh figures similar to ipywidgets (for better compatibility with Jupyter Lab integrations etc.)?

@GenevieveBuckley
Copy link
Contributor Author

GenevieveBuckley commented Jul 18, 2019

@GenevieveBuckley did you end up solving it? Now it's possible to have the whole Bokeh server live inside Jupyter Kernel. Did you find a way to make Bokeh figures similar to ipywidgets (for better compatibility with Jupyter Lab integrations etc.)?

No, but this might be due to lack of time rather than technical impossibility. We're really trying to come at things the other way around: trying to fit ipyvolume into bokeh, rather than fitting bokeh into ipyvolume/ipywidgets. Less work for us, if we can do that.

I think I might need to take more of a look at how to output small html/javascript snippets with ipywidgets (right now we create a standalone html page with the one ipyvolume figure in it).

@GenevieveBuckley
Copy link
Contributor Author

(Sorry, didn't mean to change the open/closed status of the issue when I replied to you)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants