Kotlin / kotlin-jupyter

Kotlin kernel for Jupyter/IPython
Apache License 2.0
1.12k stars 105 forks source link

Allow for multiple cell outputs #20

Closed holgerbrandl closed 3 years ago

holgerbrandl commented 6 years ago

Similar to python in would be nice if multiple outputs per cell would be supported.

See https://stackoverflow.com/questions/34398054/ipython-notebook-cell-multiple-outputs

altavir commented 4 years ago

BeakerX has a feature named OutputContainer it allows to define a custom layout for output cell and put multiple outputs in there. It is extremely useful, especially backed by appropriate API. I think it is quite easy to do by defining MIME type for those outputs (interactivity could be added later).

My proposal is the following (I actually designed and used something very similar for DataForge). Add implicit object called, say, val cell: CellOuptut for each cell. CellOuptut has a number of named outputs inside it including default output and a Layout, which defines how different outputs are rendered together. Cell result is automatically placed in the default output and if there is only one output, it is rendered as is without a container. The user can explicitly call something like cell.render(target = "output name", obj = myObject, renderer = <renderer and renderer options>) and the object is put into specific output. Also user can use cell.layout{} for layout configuration.

The CellOutput should not propagate between cells (each cell has one of its own), but it would be also useful to have global CellManager object, that would allow dynamic access to any cell output (of-course we will need to name cells or get references to them like val id = cell.id or cell.name = "ddd"). In that case and output could be located by two names: cell name/id and output name. It is done like this in DataForge and is a very flexible solution.

altavir commented 4 years ago

Another thing solved by output control is a rendering from inside of the cell. In current implementation, the only way to make a plot is to return it from the cell. Obviously, sometimes we want to call it from inside the cell like plot.show(), and return something else, or show multiple plots in the same output.

ileasile commented 3 years ago

So, there is DISPLAY() method which may be called multiple times per cell. You may also update displays with UPDATE_DISPLAY(). To list all notebook/cell displays, use org.jetbrains.kotlinx.jupyter.api.Notebook#getAllDisplays and org.jetbrains.kotlinx.jupyter.api.CodeCell#getDisplays correspondingly.