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

Proposal for enhancing display() #2593

Open
dsblank opened this issue Jun 21, 2017 · 9 comments
Open

Proposal for enhancing display() #2593

dsblank opened this issue Jun 21, 2017 · 9 comments

Comments

@dsblank
Copy link
Member

dsblank commented Jun 21, 2017

Since display() is becoming an IPython primitive (being automatically injected into builtins) it would be nice to make display do a little bit more. Two ideas:

First, it would be nice if display also did the work of clear_output(), and clear_output(wait=True). For example, making it work such that:

def display(*objs, clear_output=True, wait=True, **kwargs):
    if clear_output:
        IPython.display.clear_output(wait=wait)
    ...

metakernel has display that works this way and it is quite useful.

Second, it would be nice to add a sep argument (similar to print)so that we can display items on the same line:

display(item1, item2, sep=" ")

display currently puts each display in its own span, so the sep might have to be a keyword rather than arbitrary HTML to allow items to appear on the same line.

There may be other functionalities that would be nice to include in display(), but these two I run into often.

@dsblank
Copy link
Member Author

dsblank commented Jun 22, 2017

Should this go to https://github.com/ipython/ipython/issues ?

@takluyver
Copy link
Member

This is more related to IPython than it is to notebook, certainly.

I think that the 'update' mechanism we introduced recently is a more elegant and flexible alternative to adding a clear_output boolean option.

The separator gets tricky with multiple mime types - display() is doing more than producing HTML.

@dsblank
Copy link
Member Author

dsblank commented Jun 23, 2017

What is the update mechanism?

I know that a sep would be tricky, but it would be very useful.

@takluyver
Copy link
Member

@rgbkrk can probably describe it better, but the idea is that a display call can supply or request a display id, and then later calls to display can replace a previously displayed object by ID. So e.g. a progress bar can re-display itself without clobbering any other output which has been displayed by other bits of code.

@rgbkrk
Copy link
Member

rgbkrk commented Jun 23, 2017

In the notebook (or nteract or jupyterlab) with ipykernel, run:

import time
display("hey", display_id="here")
time.sleep(0.5)
display("HEY", display_id="here", update=True)
time.sleep(0.5)
display("HEY!", display_id="here", update=True);

@rgbkrk
Copy link
Member

rgbkrk commented Jun 23, 2017

Display updates only replace a single displayed output whereas clear_output clears all the outputs.

@rgbkrk
Copy link
Member

rgbkrk commented Jun 23, 2017

Second, it would be nice to add a sep argument (similar to print)so that we can display items on the same line:

I'd really love a way to display collections of rich objects inline like this: ipython/disp#3

@Carreau kicked off some starter pieces here: ipython/disp#8

@Carreau
Copy link
Member

Carreau commented Jun 23, 2017

Yes the sep is problematic as we send all the mimetype, I would prefer to teach collections how to display themselves. it is definitively challenging to display containers, as the way you expect them to be displayed highly depends on the content. A list of string should likely be displayed as a vertical list of items, why small images, you likely want them in a horizontal sequence. So there is not only a separator, but a question of layout. It also shift (some) of the responsibility of mimetype picking in the kernel, unless we introduce json pointers in the spec.

I'd also like to keep the display() API identical between Python 2 and python 3 – at least for a while.

Also wondering, is clear output necessary if you can display update with None ?

@tritemio
Copy link
Contributor

@Carreau, maybe bit OT, but it would be really nice to have an option to stack matplotlib figures horizontally instead of vertically. The horizontal scrollbar would allow to see a long list of figures without taking too much vertical space.

Use case: oftentimes I generate figures (>100) in a loop, displaying one figure at time, closing the figure and moving to the next iteration. So, I am already using display(fig). But, adding an option to stack these figures horizontally would really make the navigation much easier.

Is this been discussed somewhere? Can you point me to some open issue I can follow? Thanks.

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

5 participants