{"action":"created","issue":{"url":"https://api.github.com/repos/jupyter/jupyter_client/issues/374","repository_url":"https://api.github.com/repos/jupyter/jupyter_client","labels_url":"https://api.github.com/repos/jupyter/jupyter_client/issues/374/labels{/name}","comments_url":"https://api.github.com/repos/jupyter/jupyter_client/issues/374/comments","events_url":"https://api.github.com/repos/jupyter/jupyter_client/issues/374/events","html_url":"https://github.com/jupyter/jupyter_client/issues/374","id":316720490,"number":374,"title":"Enable rich outputs and widgets for wrapper kernel","user":{"login":"Jannick92","id":16480054,"avatar_url":"https://avatars1.githubusercontent.com/u/16480054?v=4","gravatar_id":"","url":"https://api.github.com/users/Jannick92","html_url":"https://github.com/Jannick92","followers_url":"https://api.github.com/users/Jannick92/followers","following_url":"https://api.github.com/users/Jannick92/following{/other_user}","gists_url":"https://api.github.com/users/Jannick92/gists{/gist_id}","starred_url":"https://api.github.com/users/Jannick92/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Jannick92/subscriptions","organizations_url":"https://api.github.com/users/Jannick92/orgs","repos_url":"https://api.github.com/users/Jannick92/repos","events_url":"https://api.github.com/users/Jannick92/events{/privacy}","received_events_url":"https://api.github.com/users/Jannick92/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2018-04-23T08:56:39Z","updated_at":"2018-04-24T12:36:42Z","closed_at":null,"author_association":"NONE","body":"I am trying to show plots and other widgets with my custom wrapper kernel, but am still struggling with showing rich output and managing the comms. I already made [an issue](https://github.com/jupyterlab/jupyterlab/issues/4398) on it in the jupyterlab repo.\r\n\r\nIn my own kernel i succeeded at showing the plots as an image with the display_data_for_image function of [the bash kernel](https://github.com/takluyver/bash_kernel/blob/master/bash_kernel/images.py), but i don't understand how to do that for other mime-types yet.\r\n\r\nFor convenience i made a new kernel that executes python code. \r\n```\r\nfrom ipykernel.kernelbase import Kernel\r\nfrom ipykernel.comm import CommManager, Comm\r\nimport ast\r\nfrom ipywidgets import *\r\n\r\nclass TestKernel(Kernel):\r\n  global interpret\r\n  implementation = 'python'\r\n  implementation_version = '1.0'\r\n  language_info = {\r\n      'name': 'little test',\r\n      'mimetype': 'text/plain',\r\n      'codemirror_mode': 'python',\r\n      'file_extension': '.txt',\r\n  }\r\n  banner = \"Making widgets appear\"\r\n\r\n  def __init__(self, **kwargs):\r\n      super(TestKernel, self).__init__(**kwargs)\r\n      self.comm_manager = CommManager(parent=self, kernel=self)\r\n      self.comm_manager.register_target('jupyter.widget', Widget.handle_comm_opened)\r\n      self.comm = Comm(target_name='jupyter.widget')\r\n\r\n  def interpret(source):\r\n      p = ast.parse(source)\r\n      expr = None\r\n      res = None\r\n      if p.body and isinstance(p.body[-1], ast.Expr):\r\n          expr = p.body.pop()\r\n      code = compile(p, '<string>', 'exec')\r\n      exec (code)\r\n      if expr:\r\n          code = compile(ast.Expression(expr.value), '<string>', 'eval')\r\n          res = eval(code)\r\n      return res\r\n\r\n  def do_execute(self, code, silent, store_history=True, user_expressions=None,\r\n                 allow_stdin=False):\r\n      if not silent:\r\n          try:\r\n              output = interpret(code)\r\n              stream_content = {'name': 'stdout', 'text': str(output)}\r\n              self.send_response(self.iopub_socket, 'stream', stream_content)\r\n              # self.send_response(self.iopub_socket, 'display_data', output)\r\n          except Exception as e:\r\n              self.send_response(self.iopub_socket, 'stream',\r\n                                 {'name': 'stderr', 'text': str(e)})\r\n\r\n      return {'status': 'ok',\r\n              'execution_count': self.execution_count,\r\n              'payload': [],\r\n              'user_expressions': {},\r\n             }\r\n\r\nif __name__ == '__main__':\r\n  from ipykernel.kernelapp import IPKernelApp\r\n  IPKernelApp.launch_instance(kernel_class=TestKernel)\r\n```\r\nWhat would i need to enable rich output? And how can i manage the comms to show widgets?"},"comment":{"url":"https://api.github.com/repos/jupyter/jupyter_client/issues/comments/383914390","html_url":"https://github.com/jupyter/jupyter_client/issues/374#issuecomment-383914390","issue_url":"https://api.github.com/repos/jupyter/jupyter_client/issues/374","id":383914390,"user":{"login":"takluyver","id":327925,"avatar_url":"https://avatars3.githubusercontent.com/u/327925?v=4","gravatar_id":"","url":"https://api.github.com/users/takluyver","html_url":"https://github.com/takluyver","followers_url":"https://api.github.com/users/takluyver/followers","following_url":"https://api.github.com/users/takluyver/following{/other_user}","gists_url":"https://api.github.com/users/takluyver/gists{/gist_id}","starred_url":"https://api.github.com/users/takluyver/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/takluyver/subscriptions","organizations_url":"https://api.github.com/users/takluyver/orgs","repos_url":"https://api.github.com/users/takluyver/repos","events_url":"https://api.github.com/users/takluyver/events{/privacy}","received_events_url":"https://api.github.com/users/takluyver/received_events","type":"User","site_admin":false},"created_at":"2018-04-24T12:36:42Z","updated_at":"2018-04-24T12:36:42Z","author_association":"OWNER","body":"That may be a bit more work. Start by reading about [comms](http://jupyter-notebook.readthedocs.io/en/stable/comms.html), which are they layer underneath widgets, and then look at the relevant code in ipykernel and in ipywidgets."}}
{"actor":{"display_login":"takluyver"}}