[IPython-dev] D3js and IPython

Matthias BUSSONNIER bussonniermatthias at gmail.com
Tue Jan 8 17:01:25 EST 2013

Le 8 janv. 2013 à 22:11, lecast a écrit :

> Thx. I will have a look at both the repository and the pull. 
> Returning Javascript() or HTML() is not exactly what I need. In general I always need  to publish both html and javascript within a function so that function that would correspond to make_table() from ipy_table creates both the element and the script that populates that element. 

Doesn't Javascript have an option to also pass css/html/libraries ?

> But this is mute here, since I couldn't find a way to copy final elements from the window and saving them in the notebook for good, the only thing that actually is saved is the final html object.

> I don't use inline JS anywhere there. But, if you prevent inline JS in output then you will also prevent a lot of interactivity on final output that e.g. d3 generates. I mean you need to be able to have things like onClick etc.

You can bind dynamically, but all script/onclick will probably be escaped. 
What will come is the ability to use js 'plugin' to which you can talk. you could send those 'plugin' data.
This should be more than enough to do what you want. 
In your case that would be a plugin 'table' to which you send 'json' and that render the table. 

> But if you mean that you will prohibit me from saving javascript in any form in the notebook, then I will probably have to stop pulling the new versions... 
It will be saved, it will just not be runned by default. I would vote for a config flag to allow it, which would progressively be deprecated in
a non official plugin. ANd probably a "This notebook contain Javascript, Run It" ? 

> Right now I spend all my time in Notebook, i.e. I wrote a script that converts notebooks to latex and I just write my papers in Notebook.

Have you tried nbconvert ? there is an  option for that, and we rally would like to push it forward and have testing and fixes. 
We want the ability in the notebook to have a 'download as PDF', so we would love your input on that.

> It is nice since I see my math instantly, but I need to be able to embed some javascript that appears only in those notebooks that are really papers, e.g. to replace references or make highlights ( http://i46.tinypic.com/163qyg.png ).

Oh ! This is a highly customized notebook, I would like to see the code that does it. 
It could become an extension and look definitively as things we want to do. 

> Customjs is ok unless you send the notebook to someone and don't tell them they need to have it as well. I wanted something that produces output that is easily replicable. 

Yes I do understand, but right now I can send you a notebook that does in js : 
IPython.kernel.execute('rm -rf ~/') 

You probably don't wan't that, and there are other security issues in js. 

Also in the end, we could 'detect' that some cell have data that needs some plugin and in place of that show "you need FOO-Plugin, install ?"

I was skeptical in deprecating publishing JS, but after seen Brian D3 js demo and some though I do think it is the way to go.

I really hope we can find a way to solve all those things, and feedback like that where you have a real use case of 
great things you want to to will be **really** helpfull in designing what have to be done. 


> Z wyrazami szacunku,
> Marcin Zamojski
> On Tue, Jan 8, 2013 at 8:56 PM, Matthias Bussonnier [via Python] <[hidden email]> wrote:
> Hi ! 
> It look really great : 
> A few comment : 
> Obstacle 1 
> def x(): 
>         from IPython.core.display import Javascript 
>         Javascript('alert("a")') 
> x() 
> you probably want to `return Javascript('alert("a")')` 
> Am I wrong ? 
> Obstacle 2: 
>  same : `return HTML()` I guess... 
> Please, please, please don't inline script. 
> We will in anyway prevent script in output so this will become useless anyway. 
> Which will deprecate _js_repr_ (at least make it useless) but Brian Json-handler branch 
> ill work much better to do what you want. 
> Obstacle 3/Obstacle 4 
> Will be solve with brian Json Handler branch. 
> You probably want to inject your own library in the notebook, 
> which can be done via custom.js 
> draft doc : http://elacave.lmdb.eu/~carreau/yui/classes/IPython.customjs.html
> use $.getScript(url) 
> for example : 
> $.getScript('d3.min.js') in you have d3.min.js in .ipython/profile_xxx/static/js/d3.min.js 
> You might be interesting in 
> http://epmoyer.github.com/ipy_table/
> To join effort. 
> Thanks. 
> -- 
> Matthias 
> Le 8 janv. 2013 à 17:26, lecast a écrit : 
> > This is a new thread but it is born out and related to a  previous discussion 
> > <http://python.6.n6.nabble.com/experiment-remote-execution-of-jquery-and-d3-code-into-the-browser-via-ipython-td4633053.html#a4955237> 
> > . The goal there was to live update figures created with d3js in IPython 
> > Notebook. It was suggested that a solution would be to use widgets, which I 
> > have to admit I did not have time to understand so instead I decided to 
> > create something that produces the end product I was aiming at, i.e. take 
> > output from Python, use d3js to create a table/figure, use some blackbox, 
> > have the output visible in the notebook (or be able to save it elsewhere as 
> > svg/html/png/etc). 
> > 
> > You can find an example notebook with a lot of custom tables and some 
> > figures  here <http://nbviewer.ipython.org/4484816/ipyD3sample.ipynb>  . 
> > They are all created based on data from Python, rendered in PhantomJs (in 
> > that case I just copy the html, but PhantomJs allows for conversion to other 
> > formats), and then published in the notebook. 
> > 
> > I created it for myself, so there is hardly any commenting in the file (I 
> > know, bad), but I have been using it for a few months now and it works 
> > really well. D3js has some great modern visualizations coded in and it takes 
> > only a few days to learn the syntax by doing. 
> > 
> > Personally I think it would be really nice to make it into an 
> > extension/package, but I lack experience/time to do that. 
> > 
> > 
> > 
> > -- 
> > View this message in context: http://python.6.n6.nabble.com/D3js-and-IPython-tp5001661.html
> > Sent from the IPython - Development mailing list archive at Nabble.com. 
> > _______________________________________________ 
> > IPython-dev mailing list 
> > [hidden email] 
> > http://mail.scipy.org/mailman/listinfo/ipython-dev
> _______________________________________________ 
> IPython-dev mailing list 
> [hidden email] 
> http://mail.scipy.org/mailman/listinfo/ipython-dev
> If you reply to this email, your message will be added to the discussion below:
> http://python.6.n6.nabble.com/D3js-and-IPython-tp5001661p5001692.html
> To unsubscribe from D3js and IPython, click here.
> View this message in context: Re: D3js and IPython
> Sent from the IPython - Development mailing list archive at Nabble.com.
> _______________________________________________
> IPython-dev mailing list
> IPython-dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev

More information about the IPython-dev mailing list