payne
payne

Reputation: 14177

How to access "current cell output area" with JavaScript in IPython Web notebook?

In the IPython Web notebook, I'm writing code that returns a JavaScript display object, that will display output in the cell output area.

What's the preferred idiom for the JavaScript code to reference "the current cell's output area", in a way that doesn't overlap things if there are multiple JavaScript output cells in the notebook?

(I realize that IPython JavaScript support is a work in progress).

Upvotes: 2

Views: 2149

Answers (1)

Matt
Matt

Reputation: 27843

You cannot easily get access to the output area, but when javascript is executed, it is in a namespace where a hidden div bind to a local variable named container element exist and is in the output area. you can .show() it and inject html in it it will appear where you expect it to.

See for example http://nbviewer.ipython.org/6131622

UPDATE IPython 2.0 and above.

Starting with IPython 2.0 you should access the DOM via a local variable named element in which you can append whatever you like. This tag is invisible when empty and will be automatically shown when not empty (it use a css :empty pseudo selector to apply display:none css rule).

For compatibility reason the old methods might still work for IPython version 2.0.

Upvotes: 3

Related Questions