<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class=""><font color="#0000ff">>> What's the best way to do it? Should I create a custom mime type<br>
>> "application/myapp", and extend the notebook to use the JS app for<br>
>> that mime type (if that's even possible)?<br>
><br>
> I think this opens up a can of worms (certainly relative to the approach<br>
> above).   Going this route, you start to introduce dependencies on how the<br>
> notebook is served, and you make the notebook itself less portable.<br>
<br>
</font></div><font color="#0000ff">Thanks. Could you elaborate on why this approach would make the<br>
notebook less portable?<br></font></blockquote><div><br></div><div>Right now, IPython supports plain text, markdown, HTML, "JSON", Javascript, PDF, PNG, JPEG, and SVG with "formatters".  (See:   <a href="http://ipython.org/ipython-doc/dev/api/generated/IPython.core.formatters.html">http://ipython.org/ipython-doc/dev/api/generated/IPython.core.formatters.html</a>)  You <b>could</b> write your own new formatter for your datatype, but then you're reaching into lesser-used code areas that have changed in the past.  In my experience, those are areas that <i>tend</i> to have future change risk.  (Also, your suggestion of a MIME type suggested (to me) that you were getting into dynamically probing some rendering capability in the browser, which gets more complicated).</div>
<div><br></div><div>From the use case you describe (a JSON model rendered my three.js), I would just do your approach #2:  create a completely self-contained Javascript() cell result.  The sample Javascript notebook I originally mentioned uses three.js as the example of an external library, and shows you how to navigate some of the nuances with that (e.g. the event loop):  <a href="http://nbviewer.ipython.org/github/payne92/notebooks/blob/master/00%20Javascript%20In%20Notebooks.ipynb">http://nbviewer.ipython.org/github/payne92/notebooks/blob/master/00%20Javascript%20In%20Notebooks.ipynb</a></div>
<div><br></div><div>If you care about non-WebGL cases, your Javascript code should probe for WebGL and fall back to rendering your PNG if it is not present.</div><div><br></div><div>If you care about non-Web IPython notebooks (e.g. qtconsole), return a Python object with two repr methods:  <font face="courier new, monospace">_repr_javascript_()</font> and <font face="courier new, monospace">_repr_png_()</font>.  The notebook runtime will pick the "best" based on what's available:  PNG on qtconsole, and Javascript on the Web.  (Personally, I wouldn't worry too much about this:  I think the Web notebook is the future).</div>
<div><br></div><div>-andy  </div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<font color="#0000ff"></font>
<br>
Let's take an example. Imagine I want to display 3D models in a<br>
notebook using a JS library (like three.js).<br>
<br>
Approach 1:<br>
<br>
* My cell's output contains data in several mime types: PNG with a<br>
screenshot, and OBJ (for example) with the full 3D model. It seems to<br>
me that the nbformat is designed for this (multiple MIME types<br>
representing the same logical data).<br>
<br>
* If the client understands the OBJ mime type, it displays it using three.js.<br>
<br>
* Otherwise, it just displays the PNG screenshot.<br>
<br>
Approach 2 would be to embed the entire Javascript code in the output<br>
+ <script include jslibraries> (like you suggest, and like mpld3 does,<br>
unless I'm mistaken)<br>
<br>
I guess my questions are:<br>
<br>
* Which of those two approaches is recommended by IPython devs?<br>
* Is the notebook designed for approach 1 use-case or not?<br>
<br>
It seems to me that approach 1 is cleaner while approach 2 looks like<br>
a hack, but that's just my opinion.<br>
<br>
Best,<br>
<div class=""><div class="h5">Cyrille<br>
_______________________________________________<br>
IPython-dev mailing list<br>
<a href="mailto:IPython-dev@scipy.org">IPython-dev@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/ipython-dev" target="_blank">http://mail.scipy.org/mailman/listinfo/ipython-dev</a><br>
</div></div></blockquote></div><br></div></div>