gzuidhof / starboard-notebook

In-browser literate notebooks
Mozilla Public License 2.0
1.24k stars 99 forks source link

Render ._repr_*_() if it's present #80

Closed bartbroere closed 2 years ago

bartbroere commented 2 years ago

IPython has a convention that a lot of packages follow, where you can add user friendly representations, in methods like _repr_html_() or _repr_jpeg_(). Could we adopt this convention in Starboard Notebook?

I would be willing to work on this when I have some time.

gzuidhof commented 2 years ago

Definitely, this should be part of the on-going work to bump Starboard to the latest version of Pyodide. In this update the cell output should no longer be a proxy (as it leaks memory) - instead it should look for these repr functions and fall back to a string representation.

Here's a link to the current implementation that is proxy based https://github.com/gzuidhof/starboard-notebook/blob/master/packages/starboard-python/src/run.ts#L56-L85 - it will work for stuff like Sympy and Pandas.

gzuidhof commented 2 years ago

I just released version 0.15.0, which has the same built-in _repr_*_ support without leaking stuff :)