-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
tutorials: Support meshcat running in a jupyter cell (as iframe) on Google Colab #12645
Comments
For reference, it seems like Example Binder link: EDIT: Looks like the default backend uses |
Just to expand, this difference in functionality can be reproduced in a local Docker container, per this bit: I can also install
|
The first part of this is going to be whether we can actually expose a port when running on Binder. If it happens to run the equivalent of |
And (after just trying) as you would imagine, it does not allow you to expose 7000, so no websocket connection, so no meshcat visualization. |
(so the short answer would be that using a different visualizer would be a million times easier) |
Aye, makes sense... |
Are going to therefore close this as not possible or re-scope it as use a different visualizer or rewrite much of meshcat? |
Re-scoping to achieve some level of 3D visualization on Binder. |
Also filed: meshcat-dev/meshcat#67 |
Next step is to try another |
We also have something like https://pypi.org/project/itkwidgets/ with Binder examples here: https://mybinder.org/v2/gh/InsightSoftwareConsortium/itkwidgets/master?urlpath=lab/tree/examples |
I did some experimentation with itkwidgets. I tried some of the itk examples linked above (#13182). These examples work in Binder assuming itk and itkwidgets are available. Note that the version 0.27.0 of itkwidgets is not rendering in Binder (itkwidgets issue), I used itkwidgets==0.26.1 to test. As a sidenote, I tried pip installing itk and itkwidgets directly from Binder , e.g.
But I couldn't import itkwidgets? The vtk examples currently don't work in Binder (brief explanation). I haven't explored this at all, but this disscussion seems to indicate that it might be possible? |
@BetsyMcPhail For your WIP branch, can you instead try to hack the |
If it takes too long for |
#13182 has been updated with a new notebook (tutorials/3dvisualization_tests) that has working examples from itkwidgets, open3d and pyntcloud.
Use the docker image for Binder to try locally. |
@EricCousineau-TRI do you want to evaluate this as is and decide whether/what other visualizer options Betsy should explore? |
Thanks! I've just ran through the examples and provided some feedback in the PR. |
@jamiesnape When you have a chance, per your prior comment:
Would you or Betsy have time to add a permalink link to the JupyterHub code which indicates that this is not possible? |
There isn't public code. It would be a server firewall configuration. (Also it is Binder, not JupyterHub.) |
Just for now, will re-assign this to you Russ until there're more action items for someone else. |
Just to update my thoughts on this... After talking to @rdeits a week or so ago, he mentioned that the entire meshcat network setup was actually inspired by the way that jupyter kernels work (websockets and zmq). Assuming colab is the same, it might be that the most viable option here is actually to figure out if we can piggyback on the existing websocket connection between the browser and the server instead of trying to instantiate our own. @rdeits said he had managed to do that with Jupyter once before. |
Hi guys ! I had a similar issue. I managed to get it work after "fixing" websocket, by enabling cross-traffic. Here is a working snippet enabling to render a custom javascript meshcat viewer in jupyter:
|
Ok, here's a direction which doesn't require any port forwarding, server configuration, certificates, or proxy. Rather than using a websocket, we can send commands from python to the frontend using the built-in Jupyter comms protocol. I've set up a dumb example that renders an iframe and then sends messages to it from Python here: https://github.com/rdeits/meshcat-python/blob/jupyter-comms-demo/comms.ipynb This means:
This would require some changes to meshcat to support sending messages this way instead of over ZMQ, but it might not be too bad. Essentially, we'd have to replace the calls to @RussTedrake this is what I was referring to when I talked about using the Jupyter comms protocol itself. It should also work on Colab (although I haven't tested) since it's the same underlying mechanism that things like altair and ipywidgets use. |
@duburcqa -- thanks. That one we knew how to do, and Robin already has it basically available in the @rdeits -- awesome! it worked exactly as expected on my local machine, but my first copy/paste to colab did not: |
Ah, just found this: https://github.com/googlecolab/colabtools/blob/master/packages/outputframe/lib/index.d.ts which does have APIs that refer back to https://jupyter-notebook.readthedocs.io/en/stable/comms.html It looks like this example is what we want: |
Made some progress, but hit (I think) a missing feature/export in colab. I've asked on stackoverflow. |
OK, I have a proof of life, albeit with the probably inefficient version of opening a new comm channel for every message. |
Woot! I think I've get everything working now (though it will get more efficient if the stackoverflow generates a response). |
…" mode. Resolves RobotLocomotion#12645. (woohoo!)
@RussTedrake We would also like to integrate Pinocchio within Colab/Binder with Meshcat viewer. Did you manage to integrate the solution into Drake framework? @duburcqa Did you manage to also provide this portage within your framework? |
@jcarpent -- see also #13038, which is now almost complete. There are a lot of details and moving part that I could help you understand if you like.
|
Dear @RussTedrake, Thanks a lot for the clear and detailed answer. I'm also following #13038: this is a very interesting feature that may be useful to a lot of people. Thanks again @RussTedrake for your very helpful feedback. |
I definitely considered |
Perfect. I totally understand. |
Hello, I tried to embed meshcat in a jupyter cell on binder: https://github.com/nim65s/binder-meshcat-pinocchio-test. It is mostly a copy-paste from meshcat-dev/meshcat-python#74, with the following changes:
A few comments about that:
I'd be glad to discuss a bit about this, before going further and opening PRs ; so if you have any comment or subjection, please don't hesitate :) |
For reference / archival or if anyone is interested -- Here's some code that I've used in Deepnote. It automatically opens up a Meshcat display in a new browser tab. import meshcat
import os
from IPython.display import HTML, Javascript, display
with open(os.path.dirname(meshcat.__file__) + '/viewer/dist/main.min.js', 'r') as f:
main_min_js = f.read()
def js_esc(data):
bs = '\\'
return data.replace(bs, bs*2).replace('\n', bs + '\n').replace("'", bs + "'")
body = f"""
<div id="meshcat-pane" style="height: 100%; width: 100%; overflow-x: auto; overflow-y: hidden; resize: both"></div>
"""
title = f"""
MeshCat
"""
mine = """
document.meshcatViewer = new MeshCat.Viewer(document.getElementById("meshcat-pane"));
"""
js = main_min_js + ";" + mine
escaped_body = body.replace("\n", "\\n")
js = f"""
var newWindow = window.open("", "meshcat");
newWindow.document.title = '{js_esc(title)}';
newWindow.document.body.innerHTML = '{js_esc(body)}';
var script = newWindow.document.createElement('script');
script.text = '{js_esc(js)}';
newWindow.document.head.appendChild(script);
window.document.meshcatViewer = newWindow.document.meshcatViewer;
console.log("MeshCat is ready!");
"""
display(Javascript(js)) This allows for opening the window without needing an https server for the HTML code. It also allows code in notebook cells to inject Javascript code into the meshcat tab. It does not resolve any problems related to the meshcat websocket messages; those would still need to come in via a wss socket. |
I'm going to close this as "Won't fix", since nobody is asking for it currently. We can reopen it if/when there is interest. |
Problem
We don't have an example of doing 3D, animated visualization on Binder.
Reproduction
Based on the
meshcat-python
demo:https://github.com/rdeits/meshcat-python/blob/549171bcf11ee422904fcf4858e231a354191eae/demo.ipynb
I briefly tried out showing a Jupyter cell in Binder:
The Meshcat server could run, but I could not connect to the client.
I (very naively) tried to use
http://{ip}.0.0.1:7000/static/
, where{ip}
is the publicly-visible IP address from the running instance on Binder:But this did not work. I'm assuming we may have to get creative (if it's at all possible) to show the visualization on the client side.
Potential Solutions / Prototypes
Per this comment,
meshcat
may be viable, either via static HTML or by forwarding ports.Other alternative being investigated are other direct / indirect
three.js
solutions, such as:itkwidgets
(vtk.js
)three.js
directlyPrototypes
tikwidgets
(vtk.js
)meshcat
static HTMLmeshcat
via forwarding ports via Binder's mechanismsEvaluation
TBD
UPDATE (2020/01/28): Per Jamie's comment below, the best solution for this may be to not use MeshCat, but instead another visualizer that can better handle the Binder-/JupyterHub- style workflow.
For displaying the widget / cell pointing to the appropriate cell, we may need to somehow specify the
host
option inmeshcat
, but it's unclear how to do so. Some relevant lines of code:https://github.com/rdeits/meshcat-python/blob/549171bcf11ee422904fcf4858e231a354191eae/src/meshcat/visualizer.py#L42-L44
https://github.com/rdeits/meshcat-python/blob/549171bcf11ee422904fcf4858e231a354191eae/src/meshcat/servers/zmqserver.py#L167-L173
If the notebook is run locally, everything is fine; see #12646 for an example.
\cc @RussTedrake @TobiaMarcucci
The text was updated successfully, but these errors were encountered: