n-riesco / ijavascript

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

asynchronous graphical output #93

Closed Fil closed 7 years ago

Fil commented 7 years ago

I'd like to produce images and push them asynchronously using $$.svg() or $$.html(), but it seems that only the first thing I send makes it to the screen.

$$.async()
i = 0;
s = setInterval(_ => {
    i++
    console.log(i)
    $$.html('html=' + i)
    if (i>=5) clearInterval(s)
}, 500)

=>

1
html=1
2
3
4
5

Is there a way to fix this?

n-riesco commented 7 years ago

I'm going to mark this issue as a bug (I've checked the json schema for .ipynb files and multiple outputs are allowed).

IJavascript used to allow multiple results per cell, but recently I decided to enforce a single output policy, because some frontends (most notably the Jupyter notebook) don't handle multiple results gracefully; see the screenshot below).

Once I publish the fix, you should be able to do as below:

screenshot from 2017-01-28 17-14-01

rgbkrk commented 7 years ago

@n-riesco You should publish multiple display_data rather than execute_result within IJavaScript.

rgbkrk commented 7 years ago

The only thing that should end up as execute_result should be the last result -- the result from vm.runInContext (and should be the one to be inspected). Everything else should come across on display_data, stream, or error all of which can be asynchronously emitted.

This whole time I thought you were taking an artistic choice for why it was a global assignment $$html = .... Is there a way to set other headers for a full display_data as well? I want to start using the transient object to set display_ids.

n-riesco commented 7 years ago

@rgbkrk Oh! I see this is new in v5.1 of the messaging protocol.

n-riesco commented 7 years ago

@Fil I've updated the nel package and extended the signature of the functions in $$ with the argument keepAlive; e.g. $$.text("Hello, World!", true); $$.text("Bye!");.

At the moment, IJavascript doesn't implement the transient API in protocol v5.1. It simply sends multiple responses (which most frontends won't handle gracefully).

If you want to try it out. You'll have to ensure IJavascript is using the latest version of the nel package.

Fil commented 7 years ago

it works 👍