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

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

Closed
mjbright opened this issue Jul 16, 2016 · 9 comments
Closed

Comments

@mjbright
Copy link

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?

@dsblank
Copy link
Member

dsblank commented Jul 16, 2016

I think you can:

from metakernel.display import display

and that should work.

@mjbright
Copy link
Author

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]

@dsblank
Copy link
Member

dsblank commented Jul 17, 2016

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.

@mjbright
Copy link
Author

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-
.

@dsblank
Copy link
Member

dsblank commented Jul 17, 2016

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!

@blink1073
Copy link
Member

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.

@dsblank
Copy link
Member

dsblank commented Aug 22, 2016

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

@dsblank
Copy link
Member

dsblank commented Aug 22, 2016

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

@dsblank
Copy link
Member

dsblank commented Mar 13, 2017

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

@dsblank dsblank closed this as completed Mar 13, 2017
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