n-riesco / ijavascript

IJavascript is a javascript kernel for the Jupyter notebook
Other
2.18k stars 187 forks source link

Magics like %%HTML #71

Closed brettvitaz closed 8 years ago

brettvitaz commented 8 years ago

Is there a way to use magic commands like %%HTML (to render HTML in the output)?

I am considering this as a way to test out React components.

BTW, I'm using this library in a set of "useful" docker containers I've created: https://github.com/brettvitaz/docker/blob/master/python/jupyter/node/Dockerfile I am interested in contributing if you'd like any help

n-riesco commented 8 years ago

IJavascript already provides the ability to output HTML. There are two ways to achieve this:

I'm also interested in getting React and other libraries like Plotly.js working (see #66 ). Currently, the main difficulty is to inject the library (React, Plotly.js, ...) in the frontend (because that's where the HTML output will be run).


About the dockerfiles, see as an example the use I make of them in the test folder, here and here.

Currently, this dockerfiles install IJavascript from the npm repository. I'm planning to change this, so that the containers uses the local installation of IJavascript.

Could you open a new issue to describe what Dockerfiles you'd like to see in IJavascript?


IJavascript avoid magics by design (because they break Javascript syntax, see #43 ).

brettvitaz commented 8 years ago

Thank you for your response! I see now that you've implemented HTML in the cell output.

I have read your explanation for why magics break Javascript syntax, and while I somewhat understand the bang (!), I don't believe that is valid syntax to write %this or %%that in the beginning of a line or code cell. My preference is that, in the spirit of the Jupyter Python implementation and to make it a more seamless transition experience, these kind of magics could be implemented. My feeling is that much is being left on the table in regards to feature parity without a magics implementation.

After reading your response, I realize why it isn't going to be as easy as I thought to render React elements on the DOM. Is it possible to expose the browser window or document? I have noticed that Jupyter Python %%javascript implementation executes JavaScript in the browser, but I have not yet tried to identify the mechanism for this.

I will open a new issue regarding what I'd like in a Dockerfile.

n-riesco commented 8 years ago

On 25/07/16 01:40, brettvitaz wrote:

I have read your explanation for why magics break Javascript syntax, and while I somewhat understand the bang (!), I don't believe that is valid syntax to write |%this| or |%%that| in the beginning of a line or code cell. My preference is that, in the spirit of the Jupyter Python implementation and to make it a more seamless transition experience, these kind of magics could be implemented. My feeling is that much is being left on the table in regards to feature parity without a magics implementation.

The IJavascript kernel is used in more contexts than the Jupyter notebook. Since magics are unnecessary and don't play well in other contexts, I have no plans to support them or accept any PRs to support them.

If you do need magics, I'm aware of at least two other Javascript kernels that support them: ijs and jupyter-nodejs.

After reading your response, I realize why it isn't going to be as easy as I thought to render React elements on the DOM. Is it possible to expose the browser |window| or |document|? I have noticed that Jupyter Python |%%javascript| implementation executes JavaScript in the browser, but I have not yet tried to identify the mechanism for this.

I don't understand this request. If you want to run code on the browser's window or document you need to inject this code in the browser (so that the browser runs the code).

Could you open another issue and give an example of what you want to do?


I'd like to keep all the discussions on magics under issue #43. Please, continue the discussion there.