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
Close a widget but the associate '<div class="output_area">' still exists #1845
Comments
Good point. The easiest way to get rid of it is to put all of your widgets inside of a VBox: from ipywidgets import Layout, Button, Box, VBox
from IPython.display import display
items = [Button(description='example') ]
box1 = Box(children=items)
box2 = Box(children=items)
box3= Box(children=items)
display(VBox([box1, box2, box3]))
box2.close() I don't think the notebook has the concept of removing one of the outputs once they've been displayed (without clearing all of the outputs), so it might be tricky to get the output container to actually be removed. |
The widget is put into the output at
|
Thanks for help
|
Why not display the empty widgets vbox at the very start, so you know it's displayed, rather than trying to guess if it is displayed? Or having your update function just update, and then you are responsible for displaying after updating? Or just always displaying the widgets box in your function, regardless? Edit: to be clear, I'm still not sure what sort of interaction you're wanting, so I'm suggesting lots of alternatives |
There is also an def cb(w, **kwargs):
print(w)
print(kwargs)
box1.on_displayed(cb)
box1 Does that help? |
Hi there, Thanks for a great and useful library. I just wanted to flag that this particular issue is causing important problems in the popular progress bar library I haven't had time to look properly but I am not sure if the tqdm issue could be solved using the Thanks in advance |
@Zulko, thanks for pointing this out. This may take a change in the notebook to handle deleting an output from a cell. I just checked, and there is the same problem in JupyterLab - closing a widget leaves behind the output container, which has a small height. |
Hi, @jasongrout , sorry for the late response. |
I've also been thinking about this. I think we can safely just set that output area to have I'm glad you found something that works in the interim! |
I think it is safe to delete the widget data as well in most cases (eg. tqdm progress bars). One could introduce a flag to keep the data, to keep it accessible in case one really needs it. |
I set this to 7.2, to investigate just hiding the div, without deleting the view (which requires changes in the notebook, it seems). The problem with just hiding the div is that it looks like the widget is gone, but if the notebook is saved and opened again, we'll probably see the widget text there again since the output data is still there. |
Another workaround: Create a single Output widget that things like those scrollbars are redirected to. When the scrollbars are finished, clear the single Output widget. |
…ew and delete the model id from the view mimetype. As a new convention, an empty string for the model id indicates that the view was explicitly removed and should be hidden. Fixes jupyter-widgets#1845 This actually doesn’t quite remove all of the empty space in JuptyerLab because there is an extra nesting of containers for rendered outputs, but it does make it better, and does seem to remove space in the separate (simplified) output area views.
notebook 5.6.0 breaks this again as it adds a run_this_cell div box to every output area with a padding of 5 so the space grows by 10 pixels for every close operation. |
The nested progress bar creates white space after each iteration. This is still unresolved, check: tqdm/tqdm#433 jupyter-widgets/ipywidgets#1845
FYI I identified the source of the problem in JupyterLab -- each removed output is nested in some two additional divs: <div class="p-Widget p-Panel jp-OutputArea-child">
<div class="p-Widget jp-OutputPrompt jp-OutputArea-prompt"></div>
<div class="p-Widget p-Panel jp-OutputArea-output p-mod-hidden"></div>
</div> While 2nd inner div with .p-Widget.jp-OutputPrompt.jp-OutputArea-prompt:empty {
padding: 0;
border: 0;
} This is far from perfect as still the internal DOM grows with empty divs, we just don't see that anymore. |
Neither the notebook nor JupyterLab really support an output removing itself, so any 'solutions' here in the ipywidgets repo are only hacks to make the display appear gone (but the output isn't really gone). That's why the workaround is so brittle and fragile. In that sense, the issue is closed as "can't fix" because it's out of ipywidget's hands. To approach getting rid of top-level outputs (including widgets), some options are to put the outputs in an output widget (which can get rid of outputs), or use the I've opened another issue to document some of these workarounds: #2215. |
@nanoant - if you have an idea of how to truly do this that I've missed, or want to help documenting some approaches for dealing with this issue (including your visibility workaround), please consider submitting a PR to here, or jupyterlab or notebook as appropriate. I didn't realize there was a |
we could also solve this via CSS variables .p-Widget.jp-OutputPrompt.jp-OutputArea-prompt:empty {
--jp-border-width: 0;
--jp-code-padding: 0;
} I think once @nanoant’s solution is added to the CSS, there’s no real need to get rid of the areas: I doubt they use up too much memory or have a performance impact |
That css touches only JLab Dom elements, not ipywidgets elements. Would you mind opening this issue in jupyterlab? |
Here is an additional annoyance caused by those lingering output areas from closed widgets. GitHub's HTML preview renders the
This happens despite Moreover, when I use tqdm_notebook, I see |
Are we gonna solve this issue in ipywidgets or jupyter? As of today (ipywidgets 7.5.0, jupyterlab 1.0.1, this empty div problem is still there. |
The problem actually isn't just to remove the no longer needed div block, but the problem happens because the output gets broken up into multiple divs, each with padding, so even if that temporary HBox is completely removed the padding problem is still there. So not only it needs to remove itself it also needs to potentially reconnect the split up into multiple divs "stdout" output. So it needs to be able to reach out to the parent and tell it to rewrite the whole tree, while (1) removing the unwanted div (2) re-merging the 2 divs that it split when it was created (or practically the next
print() was started in a new div..
For example with tqdm that so many people complain about the vertical whitespace. The problem happens because tqdm breaks up the stdout/stderr streams and they each end up in a dedicated
and before and after divs with the split content:
It is because those divs have css Here is the modified hack for jupyter nb, that removes the vertical whitespace by mucking with css. So the hack is to override the css not to have the padding for those divs. And voila, there is no vertical space anymore. (This of course may make some IPython.display mixed output appear slightly closer to each other) Note that the exact naming of the class may change in the future, so this is correct for the notebook server is: 6.0.3
add to
but it may not be what you want as it'll affect all your other nbs. You will need to reload your notebook for the new css to be picked up. And if that file didn't exist and you have just created it, you may have to restart the jupyter server too.
Now if you run a bunch of tqdm's as in the example below, you no longer have vertical whitespace injected when it gets removed:
If the vertical space shows up still you either did something wrong, or you run a different jupyter server, or perhaps you have something else overriding the css. To debug the crazy world of multiple css definitions overriding each other, use firefox's or chrome's DOM Inspector (Ctrl-Shift-I). Point to the part of the HTML you're interested in and it'll show you all the involved css and which one overrides which (you may have to click on the little pointer image first to activate the inspecting mode). See the image with all the important bits covered in this post highlighted. |
1. Hide all empty divs caused by display_javascript. A related discussion can be found here: jupyter-widgets/ipywidgets#1845 2. Force the load of jQuery, Datatable and datatable display to run in sequence. Note, Datatable is a plugin of jQuery. For the javascript to work, jQuery has to be available, then Datatable is setup correctly, then the code uses jQuery and Datatable to render. 3. Try catch some of the code to avoid racing condition. Any error thrown will ruin the execution of javascipt in the cell, and potentially cause the facets to be rendered in a broken way. Change-Id: Id4fd0a674005ae17f615604dd246aa6515aa64b3
Since 7.0 widgets in notebook are rendered in
<div class="output_area">
,but when I close a widget, the associate
<div class="output_area">
still exists.output:
How could I remove this part ?
The text was updated successfully, but these errors were encountered: