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
Jsd3 #1386
Jsd3 #1386
Conversation
Quick q: why do we need to load d3 ourselves? I'm not too happy about enshrining a particular JS library right away... I mean, from what I've seen d3 is awesome, but I'd prefer if we could take a more hands-off approach there, and let various users and projects figure out which JS tools they end up using. |
There are two aspects:
Point 2 is an annoyance, point 1 has to be solved and the simplest way Cheers, Brian On Tue, Feb 7, 2012 at 9:33 AM, Fernando Perez
Brian E. Granger |
I think it will be great to make it more general to be used other than d3, but it might be a good idea to start with one framework before it gets to complicated. It will be nice that a codecell can run javascript, but there is a good chance that arbitrary can totally mess up the whole notebook DOM. My earlier hacking uses IFRAME or open a new window to avoid that (e.g. https://github.com/cschin/IPython-Notebook---d3.js-mashup). It seems to me we need some "namespace" to constrain about what and where the javascript can manipulate. I don't have a good solution except the IFRAME thing now. |
I saw this on the list and got really excited about it. jQuery has a getScript method for dynamically loading a file which seems to work regarding issue 2. With a sym link to an external d3 dir in frontend/html/notebook/static
works as expected. For security reasons, you can't load local resources via "file:///*" urls but if you add a mechanism to expose additional static directories via the webserver then that would let people load any code they want. |
I wasn't aware of the getScript function of jquery. That definitely That allows the community to add new JS packages. Someone could add On the security side of things: it is impossible to prevent the JS On Tue, Feb 7, 2012 at 10:35 AM, Andy Wilson
Brian E. Granger |
This addresses issue #879 |
On Tue, Feb 7, 2012 at 11:31 AM, Brian E. Granger
And that's OK: IPython is a full-blown, system-level shell with zero |
Perhaps require.js could help with this? |
For the security reasons you've outlined, executing any externally-linked javascript within the notebook is a bit dangerous. If malicious code ended up at the other end of any external link (or was injected along the way) that would be a very bad thing. Also external links require internet connectivity, which can sometimes be a frustrating dependency. |
On Tue, Feb 7, 2012 at 3:43 PM, Andy Wilson
We are only executing JS code that come from the user's python code. But keep in mind: IPython is already like a big gun. With regular In [1]: %run danger.py and create this type of destruction. Bottom line: you have to trust Cheers, Brian
Brian E. Granger |
I'm thinking of CDN-hosted code. Maybe I'm misinterpreting the CDN thing, but in my mind that means a link to some .js files that are hosted on some server(s) somewhere. I agree that something like But |
On Tue, Feb 7, 2012 at 4:46 PM, Andy Wilson
Yes, the CDN does introduce an extra indirection of trust.
But we (IPython) won't load code from the CDN. The only way to load I guess another way of saying it is this: the CDN example makes it
Brian E. Granger |
This makes sense. I was concerned about a CDN-hosted copy of d3.js being included in the notebook by default. If there is a way for users to specify their own js files then does d3 need to be included at all? If someone wants d3, then he/she can just make that part of their user js files. |
A user can definitely put any JS code they want into the following dir: IPython/frontend/html/notebook/static And refer to it in the code as: /static/... The only thing that would change that is if they were using a On Tue, Feb 7, 2012 at 8:33 PM, Andy Wilson
Brian E. Granger |
Is this ready to merge. I don't think we should include d3. On Tue, Feb 7, 2012 at 8:37 PM, Brian Granger ellisonbg@gmail.com wrote:
Brian E. Granger |
I think it would be fine if a user want to put any javascript lib, he/she can do himself/herself. d3.js is just one of a lot possibles interesting js libraries. |
In the meantime, does it make sense to have a new window just for displaying dynamic content? I am looking into the handlers.py to see a potential way to do that within ipython. |
The dynamic content should definitely be inline as it is now - at the On Tue, Feb 7, 2012 at 8:50 PM, Jason Chin
Brian E. Granger |
good point. I forget we can use JS to put the element any place. My original though it more like to open a new notebook, but it has only output cell for dynamic content. This will allow developing some dynamic visualization easier. |
We really want the dynamic content on the same page - all of the On Tue, Feb 7, 2012 at 9:34 PM, Jason Chin
Brian E. Granger |
Here is a screen shot using the "Javascript" function: <img src="https://github.com/cschin/IPython-Notebook---d3.js-mashup/raw/master/images/example3_d3.jpg" /img> from this notebook. I also have an experimental one: <img src="https://github.com/cschin/IPython-Notebook---d3.js-mashup/raw/master/images/example2_d3.jpg" /img> from this notebook where I move the zmq / websocket bridge that sends javascript to a iframe into the handler.py. No extra server is needed. One advantage of this setup is that one can control the animations by python code and it could be used to make two way communication too.) |
Thanks for those, @cschin, I just edited your post to inline the figs so the post would read better, left content unchanged. |
Adding Javascript output handling to the notebook.
Adding Javascript output handling to the notebook.
Adding handling of dynamic javascript output to the notebook. I take the JS string and simply call eval on it. The enclosing scope has the element so the JS code can insert things into the DOM at the right point on the page. The code is not eval'd when the notebook is loaded or cells are pasted - only when they are executed.
Here is an example:
Currently, the full jquery/jqueryui libs are available for use. The JS classes that we use in the client are also available, so users can muck with the notebook itself. This includes running code in the kernel. BUT, the kernel will need to be refactored to pull that off. Once that is done, we should be ready for manipulate/interact style things.
Do we want to ship d3 and load it in the notebook for people to use? It really needs to be loaded in advance by us.
I can't wait to see how people use this!