Reputation: 158
I'm currently playing with Cling(C++ interpreter) and it's jupyter kernel and I would want to display an image inside Jupyter notebook using some kind of C++ function similar to IPython.display. What would be the best approach for that?
Update
Thanks for replies, I'm currently digging into both options to check what has a somewhat stable release on Windows and will be back probably next week(a lot of other work at hand right now) with comments on each of it.
Upvotes: 0
Views: 480
Reputation: 1645
I recommend you check out the rich mime type rendering feature of the xeus-cling
kernel.
For any type, you can override mime_bundle_repr
function. It is picked up through argument-dependent lookup and your object will be magically displayed inline in the Jupyter notebook.
xeus-cling also support Jupyter interactive widgets and quick documentation.
You can try it live online by clicking on the "Launch Binder" button at the top of the README page for the GitHub repository.
Upvotes: 1
Reputation: 196
Would this do what you need? From cling/tools/Jupyter/Kernel.cpp:
/// Push MIME stuff to Jupyter. To be called from user code.
///\param contentDict - dictionary of MIME type versus content. E.g.
/// {{"text/html", {"<div></div>", }}
///\returns `false` if the output could not be sent.
bool pushOutput(const std::map<std::string, MIMEDataRef> contentDict) {
Upvotes: 2
Reputation: 27843
The feature need to be implemented at the kernel level, that is to say, if cling itself does not give you the escape hatch to do it, you likely cant.
Technically under the hood, when you display something, cling will send a display_data
message, which contain a mimebundle (a mapping form mimetype to data), so you need to hook into the kernel itself to do so.
I don't believe it is in Cling yet, though the QuantStack folks did a demo recently at JupyterCon (video not online yet) where they showed widgets in their Xeus-Cling kernel.
I would thus strongly encourage you to try xeus-cling, and ask the developers there (open an issue on GitHub, or try the Gitter channel they are responsive).
Upvotes: 2