Calysto / metakernel

Jupyter/IPython Kernel Tools

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

display() just prints class of object when using %%python cell magic

mjbright opened this issue · comments

I want to be able to invoke some IPython graphics/interaction functionality from the metakernel_bash kernel.

When I try

%%python

from ipywidgets import *
from IPython.display import display
from IPython.display import HTML

html='<b> some bold text </b>'
display( HTML (html ))

it simply prints <IPython.core.display.HTML object>.

NOTE: I know that if I set retval, it will correctly render the HTML, but this is not a solution to my problem.

What I really want to be able to do (and I get the same behaviour) is to run from a bash kernel cell:

ipython test.py

where test.py contains:

from ipywidgets import *
from IPython.display import display
from IPython.display import HTML

html='<b> some bold text </b>'
display( HTML (html ))

Can you suggest a workaround to be able to do this?

I think you can:

from metakernel.display import display

and that should work.

On 16 July 2016 at 23:26, Doug Blank notifications@github.com wrote:

from metakernel.display import display

Thanks a lot Doug, this works for the %%python cell magic and that's
already really useful.

If you have an idea also for the case below where I invoke IPython that'd
be great
(I am really interested to see how we can provide "native"
graphics/interaction for the bash kernel without "visibly" dropping into
python

  • my ipython test.py call below could be wrapped up into a bash function
    in an rc file).

I tried it - fingers crossed - in my test.py which I invoke as
ipython test.py
in a metakernel_bash cell, but this still just displays


<IPython.core.display.HTML object>

My test.py contains

from ipywidgets import *
#from IPython.display import display
#from IPython.display import HTML
from metakernel.display import HTML
from metakernel.display import display

html='<b> some bold text </b>'

display( HTML( html ))

[image: Inline images 1]

You might want to take a look at https://github.com/calysto/matlab_kernel @blink1073 has done quite a bit of work to make plotting work there. I suspect some of that could be reused in metakernel proper, which would aid in making it work in the bash kernel.

Thanks Doug, I will take a look ... later though (preparing to present at
EuroPython on Friday).
I managed to do something equivalent of what I was asking for, for now, so
I'm good to go.

Actually, I do have plotting, images, html, js insertion all working via
bash functions but it will be useful to see how others have achieved
similar things.
Especially as I'd like to make some pull requests later.

On 17 July 2016 at 15:08, Doug Blank notifications@github.com wrote:

You might want to take a look at https://github.com/calysto/matlab_kernel
@blink1073 https://github.com/blink1073 has done quite a bit of work to
make plotting work there. I suspect some of that could be reused in
metakernel proper, which would aid in making it work in the bash kernel.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#99 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABywLfcvMNVq12joc44AMYIfUtGBBRrQks5qWilfgaJpZM4JOEp-
.

Good to hear that you are making due. Will you be presenting using what you are creating? If so, please do send a link!

Look forward to some PRs. Thanks!

There may be pieces of image handling that can be factored out, but I think there is always going to be a kernel-specific way of handling images. See for example the way it is handled in Thomas' bash_kernel.

I think I made a break through in being able to use IPython's display directly. Was able to get matplotlib to work in a metakernel language (calysto_scheme):

screenshot from 2016-08-21 22 06 42

The above requires the %matplotlib notebook magic, and only "notebook" works for now.

I think we can close this for now. If there is a specific kernel or problem, we can open a new, specific issue.