googlecolab / colabtools

Python libraries for Google Colaboratory

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add Ipywidgets support

joseFranciscoDiez opened this issue · comments

Widgets are the most widespread way to provide interactivity with the user in Jupyter notebooks.

Google Colab should support ipywidgets or provide an alternative.

Ref https://stackoverflow.com/questions/47269168/ipywidgets-with-google-colaboratory

commented

Also see #6

Hi,

As many I'm super interested by that feature support and wanted to know if there was any news about it?

Cheers,

Thomas

commented

Are there specific widgets or scenarios that you are interested in?

@blois : Yes absolutely :)

Here is a typical example I would be keen on running in Google Colab:

image

Widgets used: Box, Dropdown, HBox, IntSlider, Label, Textarea, VBox

You can play live with it in Binder if you can bear with the slow startup time (just need to execute the cells): https://mybinder.org/v2/gh/colour-science/colour-playground/master?filepath=playground%2Fcolour.ipynb

@blois, also, some tqdm (a progress bar) users need to run the tqdm on CoLab, which needs ipywidgets to work.
REF tqdm/tqdm#558

@blois support for ipyvolume or any other interactive 3d plot widget would be great!

@blois, ipyleaflet is another widget that would be very useful to see in Colab. Colab notebooks would be a great way forward for Python users of Google Earth Engine to collaborate, and here, ipyleaflet in Jupyter notebooks is currently among the recommended/favoured options for visualising tiled maps created from analyses. There are workarounds, but support for ipywidgets would be great. Thanks.

Adding pythreejs to the bunch!

As a core jupyter-widgets / ipywidget dev I want to let you know we are interested in support on colab. Feel free to reach out to us for help or discussion in care you need help:

cc @jasongrout @SylvainCorlay @vidartf @mwcraig

Adding ipysigma to the bunch.

I'd also like to see ipyevents in the mix...I am a little biased, though, since I wrote it. But including ipyevents would also allow astrowidgets.

Adding itk-jupyter-widgets, interactive Jupyter widgets to visualize images in 2D and 3D, as another example in the vibrant ipywidgets ecosystem that would be helpful for colab adoption.

I need this too!

commented

I'd just like tqdm progress bars to work nicely, that would be good...

Me too!

Another vote for supporting tqdm!

@diego888
See this tqdm/tqdm#640

If need to use tqdm on colab immediately.

Or you can wait until it is merged into master.

+1
Need this :)

+1, would be great if Slider, Checkbox, Combo, Select widgets will become available

commented

@chrisbol - the basic slider/checkbox/combo widgets should now be working. There are a couple of limitations and rough edges but it's worth a try.

We appreciate all of the interest and will continue to work on improvements in this area.

Please feel free to open bugs on issues and we'll see what we can do to unblock.

@blois Super happy you folks are working on ipywidgets! How do I try it out?

@blois Oh, I just had to close and re-open my notebook.

I tried Ipywidgets and I am able to get the slider. But no output is displayed when I move the slider. Please see my screenshot below. Do I need to do anything other than import the module?

image

commented

Right now the contents of output widgets are not being displayed. It's being used by @interact.

The output widget itself is fairly complicated in how it routes messages, we're evaluating how best to handle it.

This is still not working:

import ipywidgets as w
w.Button()

IPKernelApp] WARNING | Widget Javascript not detected. It may not be installed or enabled properly

Another scenario would be visualizing a list of 2D images with Menpo. It keeps showing the IPKernelApp error with Colab:

%matplotlib inline
import menpo.io as mio
from menpowidgets import visualize_images
images = list(mio.import_images('/path/to/images/'))
visualize_images(images)
commented

Currently Colab only supports the ipywidgets widgets, see #498.

The warning 'Widget Javascript not detected'- do you know what version of ipywidgets is installed?

https://colab.sandbox.google.com/gist/blois/249a58c98f8f3a2ce672dc9a1c03228c/widgets.ipynb

OK, it works now, thank you. Any suggestion on how to preview a list of images in an usable way?

On a related note, widgets are supported on kaggle, but cannot be embedded into HTML notebooks currently. jupyter-widgets/ipywidgets#2360 (comment)

commented

I'm working on rendering output widgets right now, otherwise there are two other open widgets issues:
Support custom widgets: #498
Persist widgets during notebook save: #516

There is an issue with the Image() widget which hangs when the comm is opened.

Minimal non-working example:

import ipywidgets
ipywidgets.Image()

(No data is provided, so a broken image icon should be shown. Instead, the runtime just hangs.)

More complete non-working example:

import ipywidgets
import numpy as np
from matplotlib import cm
import PIL.Image
data = cm.viridis(np.random.random((32,32)), bytes=True)
img = PIL.Image.fromarray(data)
ipywidgets.Image(value=img._repr_png_(), format='png')

Images do work - they can be captured for example with the Output() widget:

import ipywidgets
import numpy as np
from matplotlib import cm
import PIL.Image
data = cm.viridis(np.random.random((32,32)), bytes=True)
img = PIL.Image.fromarray(data)
out = ipywidgets.Output()
display(out)
with out:
    display(img)

Also, the Label widget does not display values properly:

import ipywidgets
ipywidgets.Label(value="Hi")
commented

The fix for the Label widget not displaying is now live. Thanks for the report.

Since noone has mentioned it yet, could we get pythreejs support? Here is an example of what I would try to do with it: https://github.com/thwee-alchemist/pyfourd/blob/master/Untitled.ipynb

Variable inspector would be really useful to have in Colab. Please add support for it

Supporting ipyturtle would be a great for school classrooms and parents (like me) teaching their kids python.

I got the module installed via pip with no issues, but enabling it fails:

!jupyter nbextension enable /usr/local/lib/python3.6/dist-packages/ipyturtle

Output:

Enabling notebook extension /usr/local/lib/python3.6/dist-packages/ipyturtle...
      - Validating: problems found:
        - require?  X /usr/local/lib/python3.6/dist-packages/ipyturtle

Support for keplergl would be great:

https://github.com/keplergl/kepler.gl/blob/master/docs/keplergl-jupyter/user-guide.md

The widget installs fine with pip install, but the map doesn't render, and no error is generated.

There are anyway to use FigureWidget on collab ?
A support for it would be great.
From my side the widget is never display but no error appear the notebook is just disconnected momentarily.

https://plot.ly/python/figurewidget/

Qgrid is very useful for editing a dataframe.

DataTable is already helpful for exploring and filtering. But dataframe manipulation will be even better.

pls add jupyter-notify
it's very very useful to monitor the running status of cells
https://github.com/ShopRunner/jupyter-notify

Please support nbgrader, as that would make my job as a teacher so much more easier!

There is an issue when trying to use the "SelectMultiple" widget on Colab because any ctrl-click event selects the entire cell and blocks the interact control. Options are highlighted but not passed through.
Single selection and shift-select works, just not ctrl-select.

Hi @blois, would we be able to get support for our widget Clustergrammer2 (https://github.com/ismms-himc/clustergrammer2) ? It is primarily designed for single-cell high-dimensional data exploration, but also works as a general purpose WebGL Pandas DataFrame explorer

see https://clustergrammer.readthedocs.io/

Pip installation works but I'm seeing the following error in the console
Screen Shot 2020-02-06 at 1 56 32 PM

@blois, ipyleaflet is another widget that would be very useful to see in Colab. Colab notebooks would be a great way forward for Python users of Google Earth Engine to collaborate, and here, ipyleaflet in Jupyter notebooks is currently among the recommended/favoured options for visualising tiled maps created from analyses. There are workarounds, but support for ipywidgets would be great. Thanks.

@blois Please add support for ipyleaflet, which would make visualizing and interacting Google Earth Engine tile layers much easier with the earthengine-api. @tylere @davidbrochart @chrieke

Is it possible to add support for open3d JVisualizer? Would be quiet useful to easily show 3d-data although JVisualizer is still in the experimental phase. At the moment Firefox's dev-tools console just shows Error has occurred while trying to update output. Error: "Widgets module open3d is not supported" while the cell's output stays empty when trying to use it.

Icons for buttons are not rendered in colab. I'd love to see this supported.

An empty button is showed for the following code:

my_button = widgets.Button(icon="home")
display(my_button)
commented

Opened #1302

I'd like to be able to use tqdm on colab as well.

It would be amazing to get support for third party widgets!

commented

is there any hope for ipyleaflet to be included?

@blois it appears this has been implemented now - should this issue be closed?

commented

@jph00 yes, most of the issues now fall under #498.

I'm having trouble with the Play widget. The buttons don't show their icons, and button presses do not trigger any notable reaction.
Test case: https://colab.research.google.com/drive/1WE2pV0UfgRb0cfOVdCkgo7MzwCkLBdDV#scrollTo=Y8eS_TugFa6i
Note that the same code on a local Jupyter instance works properly; the four buttons have icons, and pressing the play button causes the slider to advance and the output to output, every 2 seconds.

Maybe so; not sure how I'd know, really.

commented

@Erhannis this sounds like #1302

@blois That does appear to account for the icon problem, at least; thanks. Unfortunately, while the workaround fixes the icons, the widget remains non-functional.

@AJAX6255 Well, I've gotten a !pip list from colab and from a jupyter labs workspace, now:
colab_pip.txt
jupyter_pip.txt

As per your note, I see that the ipython version for colab is 5.5.0, vs. jupyter labs' 7.16.1.
I also note ipykernel v 4.10.1 vs 5.1.4, though I don't really know what is and isn't relevant.
The jupyter-client versions are different, and there are a few differences in exactly which jupyter-related packages are installed.
The versions of ipywidgets appear to be the same.

commented

@Erhannis this looks like it may be an issue with jslink- I just opened https://github.com/googlecolab/colabtools/is.

Oh! @blois , you were right! jslink doesn't work - but the play widget does, actually! This means that while you can't bind two values together like in the docs, you can do the following:

def value_changed(change):
  print(change.new)
play.observe(value_changed,'value')

It's probably tricky to keep two objects in sync like this, without getting e.g. infinite recursion, but for what I wanted to do I only needed a unidirectional link, anyway. Thanks!

A good workaround might be link or dlink instead, that goes via the kernel, similar to observe.

@maartenbreddels Oh, you mean when observe fires it triggers/requires communication with the server? That might explain why using a different computer in my house causes my hacky "animation" to run much slower than when it's localhost, haha

Yes, since it executes Python code, which lives at the server. That's why jslink (which is handled in the browser) usually gives smoother results (but it cannot execute code).