2

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).

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

6 Comments

Updating this for the notebook 2.x and beyond: is "element" the preferred variable to reference for the output area?
IRC using element is not supported. You should use container and append to it. No need to call show anymore.
Are you sure? The docs say element: ipython.org/ipython-doc/2/api/generated/… (though the docs also still say you need to call container.show()).
I'll check, i'm 95% certain you do not need to use container.show() as the frontend css now get a container:empty{display:none}css.
The doc has been updated, and the code state that container will be removed in 3.0 now. I'll update my answer.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.