0

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.

4

3 回答 3

2

该功能需要在内核级别实现,也就是说,如果 cling 本身没有给你逃生舱,你可能做不到。

从技术上讲,当您显示某些内容时,cling 将发送一条display_data消息,其中包含一个 mimebundle(mimetype 到数据的映射),因此您需要挂钩到内核本身才能这样做。

我不相信它还在 Cling 中,尽管QuantStack人员最近在 JupyterCon 上做了一个演示(视频还没有在线),他们在他们的Xeus-Cling内核中展示了小部件。

因此,我强烈建议您尝试 xeus-cling,并询问那里的开发人员(在 GitHub 上打开一个问题,或尝试他们响应的 Gitter 频道)。

于 2017-09-09T03:04:30.503 回答
2

这会做你需要的吗?从紧贴/工具/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) {
于 2017-09-09T09:25:50.053 回答
1

我建议您查看xeus-cling内核丰富的 mime 类型渲染功能。

对于任何类型,您都可以覆盖mime_bundle_repr函数。它是通过与参数相关的查找来获取的,您的对象将神奇地显示在 Jupyter 笔记本中。

在此处输入图像描述

xeus-cling 还支持 Jupyter 交互式小部件和快速文档。

您可以通过单击 GitHub 存储库的 README 页面顶部的“启动 Binder”按钮来在线试用它。

于 2018-03-17T14:12:31.497 回答