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

Running in Google Colab #29

Open
jguerre5 opened this issue Feb 15, 2021 · 7 comments
Open

Running in Google Colab #29

jguerre5 opened this issue Feb 15, 2021 · 7 comments

Comments

@jguerre5
Copy link

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?

@jiangzhongshi
Copy link
Contributor

@albertotono
Copy link

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

@danielgrittner
Copy link

danielgrittner commented Nov 10, 2021

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)

@jiangzhongshi
Copy link
Contributor

jiangzhongshi commented Nov 11, 2021

@danielgrittner Thanks, this is quite helpful!

@skoch9 shall we integrate this into the main codebase?

@a-nau
Copy link

a-nau commented Oct 21, 2022

@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]'.

@francesco-ballarin
Copy link

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

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

Thanks!

@a-nau
Copy link

a-nau commented Dec 23, 2022

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))

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

6 participants