Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

console does not display text/plain alternative for display_data? #71

Closed
jankatins opened this issue Apr 19, 2016 · 7 comments
Closed

Comments

@jankatins
Copy link

The R kernel sends plots via display_data messages and includes a text/plain representation in the message bundle. Unfortunately, it seems that the console does not display the text/plain message:

[ipython-notebook] λ jupyter console --kernel=ir32
Jupyter Console 4.0.3

[ZMQTerminalIPythonApp] Loading IPython extension: storemagic

In [1]: plot(1:10)

In [2]:

The message bundle looks like this:

List of 3
 $ text/plain   : chr "plot without title"
 $ image/png    : raw [1:12628] 89 50 4e 47 ...
 $ image/svg+xml: chr "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlin"| __truncated__

This is IRkernel/IRkernel#262

@jankatins
Copy link
Author

This also looks wrong:

[ZMQTerminalIPythonApp] Loading IPython extension: storemagic

@takluyver
Copy link
Member

It looks like it works with the execute_result message (that generates an Out prompt), but not with display_data:

In [1]: class A():
      :     def _repr_png_(self):
      :         return b'oijoij'
      :     

In [2]: a= A()

In [3]: a
Out[3]: <__main__.A at 0x7f052871f1d0>

In [4]: from IPython.display import display

In [5]: display(a)

@flying-sheep
Copy link
Contributor

flying-sheep commented Apr 19, 2016

well I was against changing it 😉

@flying-sheep
Copy link
Contributor

well, the cause is easy to identify:

  1. handle_rich_data is called, which in turn calls handle_image and then returns True. when returning True, text/plain isn’t used.
  2. handle_image_PIL checks if the mimetype is PNG or SVG and returns if not, without doing anything.

we should make handle_image return True/False depending on if its delegated function can handle it the format.

AGAIN a bug exposed by having SVG! this is so useful!

@takluyver
Copy link
Member

Thanks, well worked out. I've just opened #77 for it, and then noticed that you've done a fix as well. You've opened a PR against your own fork of the repo, though ;-)

@flying-sheep
Copy link
Contributor

whoops

@jankatins
Copy link
Author

AGAIN a bug exposed by having SVG! this is so useful!

More "(ab)using users as guinea pigs"... :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants