[IPython-dev] experiment - remote execution of jquery and d3 code into the browser via ipython
Massimo Di Stefano
massimodisasha at gmail.com
Mon Mar 19 20:16:15 EDT 2012
Hi All,
i found this new capabilities really really interesting! it is awesome!!!
i've few questions .. i was tring to run the examples i found here :
https://github.com/cschin/IPython-Notebook---d3.js-mashup
i applied the changes in the ipython core files (adding the 2 methods)
then i was able to run the first example (congrats! it's really cool)
now going ahead i was really attracted by the other examples 2/3
in order to add a frame inside the notebook itself instead of a new page.
in example 2 i changed the path to de.js to be : ./d3.js like in the first example
then i add the import for the module 'math'.
trying ti run example 2, i see a square empty box is loaded in the notebook (a string : 404: Not Found - inside it)
then running the first lines of code a frame is added to the python notebook! :) in it i can still see the string : 404: Not Found
the rest of the code seems to don't have effects on the frame.
have you any clue on what i need to change in order to have it running ?\
thanks a lot for this, it is so cool!
--Massimo.
Il giorno Mar 19, 2012, alle ore 10:51 AM, Jason Grout ha scritto:
> On 3/19/12 9:32 AM, hugo wrote:
>>
>>
>> On 03/19/2012 09:22 AM, fawce wrote:
>>> holy mackerel that's awesome!
>>>
>>> Can you elaborate on the callback issue? Wondering why you can't pass
>>> in a callback that just makes a ws call internally.
>>
>> just that I serialize function names and the args they are called with
>> via JSON
>>
>> so for d3, the normal way you would position points in a scatter plot is
>> something like this
>>
>> d3.selectAll('circle').attr('cx', function(d){return axis(d['x'])});
>>
>> I have no good way to pass function(d){return xaxis(d['x'])}
>>
>> I could pass it as a string, but then I would need some way to determine
>> whether strings I pass should be eval-ed to retrieve callbacks or not
>> also - you would have to write javascript callbacks in string form,
>> which is ugly anyways. furthermore, in d3, it is common to define
>> scaling axes objects, and use those in your callbacks - I don't have a
>> good place to do that either.
>
>
> fawce's suggestion sounds very intriguing--make the websockets message
> passing two-way between python and javascript. The way I understand the
> suggestion, what about (in python):
>
> def mycallback(d):
> return d3.axis(d['x'])
>
> d3.selectAll('circle').attr('cx', callback(mycallback));
>
> This gets translated to the javascript code:
>
> d3.selectAll('circle'.attr('cx', function(){
> var results= send_message('mycallback', arguments);
> return interpret_results(results);})
>
> send_message sends a message back through websockets to call the
> mycallback python function with some sort of proxy object d that knows
> how to generate json messages describing the attribute accesses, etc.
> In the python side, inside mycallback, d['x'] generates the javascript
> code to access arguments[0]['x'], so what is passed back is some sort of
> javascript code like 'd3.axis(arguments[0]['x'])'. interpret_results
> then runs this code and returns the result.
>
> Thanks,
>
> Jason
> _______________________________________________
> 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