meshplot icon indicating copy to clipboard operation
meshplot copied to clipboard

Running in Google Colab

Open jguerre5 opened this issue 4 years ago • 7 comments

I'm trying to use meshplot in a Google Colab notebook, however when I use mp.plot instead of displaying the mesh all I get is:

<meshplot.Viewer.Viewer at 0x7f9ec04dfc88>

Is there any known way to get meshplot working in Colab?

jguerre5 avatar Feb 15 '21 04:02 jguerre5

Some related notes. https://github.com/maartenbreddels/ipyvolume/issues/147#issuecomment-573956486 https://github.com/jupyter-widgets/pythreejs/issues/317

jiangzhongshi avatar Jul 01 '21 16:07 jiangzhongshi

Same issue here, if you want to test this notebook, I also install miniconda on it https://colab.research.google.com/drive/104F5OJnqz2kYG8aIDchpatDX7EH8S24w?usp=sharing

albertotono avatar Jul 10 '21 16:07 albertotono

I had the same issue when I tried to plot the mesh. However, I found the following workaround:

from IPython.core.display import display, HTML

def plot_mesh(v, f):
  display(HTML(mp.plot(v, f).to_html()))

plot_mesh(v, f)

danielgrittner avatar Nov 10 '21 21:11 danielgrittner

@danielgrittner Thanks, this is quite helpful!

@skoch9 shall we integrate this into the main codebase?

jiangzhongshi avatar Nov 11 '21 03:11 jiangzhongshi

@danielgrittner thanks for the tip!

However, I tried installing it as suggested by @albertotono with conda and also by using %pip install git+https://github.com/skoch9/meshplot.git and ~~I always get the following error in colab~~:

Update: It now works with some changes, see here.

Old error was:

---------------------------------------------------------------------------
TraitError                                Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/ipywidgets/widgets/widget.py in _handle_msg(self, msg)
    754                 if 'buffer_paths' in data:
    755                     _put_buffers(state, data['buffer_paths'], msg['buffers'])
--> 756                 self.set_state(state)
    757 
    758         # Handle a state request.

/usr/local/lib/python3.7/dist-packages/ipywidgets/widgets/widget.py in set_state(self, sync_data)
    623                     from_json = self.trait_metadata(name, 'from_json',
    624                                                     self._trait_from_json)
--> 625                     self.set_trait(name, from_json(sync_data[name], self))
    626 
    627     def send(self, content, buffers=None):

/usr/local/lib/python3.7/dist-packages/traitlets/traitlets.py in set_trait(self, name, value)
   1436                                 (cls.__name__, name))
   1437         else:
-> 1438             getattr(cls, name).set(self, value)
   1439 
   1440     @classmethod

/usr/local/lib/python3.7/dist-packages/traitlets/traitlets.py in set(self, obj, value)
    578 
...
--> 692                 raise TraitError(e)
    693 
    694     def get_metadata(self, key, default=None):

TraitError: The 'target' trait of a DirectionalLight instance expected an Uninitialized or an Object3D, not the str 'IPY_MODEL_[object Object]'.

a-nau avatar Oct 21 '22 14:10 a-nau

Hi @a-nau , do you remember what change you made to fix the DirectionalLight error?

I am facing the same issue (see https://github.com/jupyter-widgets/pythreejs/issues/388 and https://github.com/googlecolab/colabtools/issues/3159), without a solution.

Thanks!

francesco-ballarin avatar Dec 18 '22 08:12 francesco-ballarin

Hi @francesco-ballarin ,

my working version is linked in my answer and here. Not tested, but this should work:

import meshplot as mp
from IPython.display import display, HTML

p = mp.plot(...)
html = p.to_html(imports=True, html_frame=False)
display(HTML(html))

a-nau avatar Dec 23 '22 07:12 a-nau