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
clear_output improvements #1563
Conversation
@@ -683,6 +690,9 @@ var IPython = (function (IPython) { | |||
// We just eval the JS code, element appears in the local scope. | |||
var element = $("<div/>").addClass("box_flex1 output_subarea"); | |||
e.append(element); | |||
// Div for js shouldn't be drawn, as it will add empty height to the area. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you hiding the entire output_area for that cell? If so, won't the javascript be unable to append things to the output area and have them show up on the screen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I am. The js can call e.show()
if it wants to draw. But it is certainly true that if there is nothing to draw, the height should be zero (right now it's ~15 px, so running a series of js calls results in infinitely growing vertical space).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, we should document the fact that the users needs to call the show method. Not sure where to put that documentation. I agree that this is a good idea though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documented in the Javascript object docstring.
These are clear improvements to the clear_output logic. Have not tested it, but the code looks good. |
This reduces flicker during common loops like: for step in stuff: clear_output() print something the timeout is flushed *immediately* on any subsequent output.
prevents growing vertical space from adding empty output_areas.
Here is a notebook with text progress bar using clear_output improvements and simple javascript progress bar using js changes. Writing a javascript progress bar is really trivial: import uuid
from IPython.core.display import HTML, Javascript, display
divid = str(uuid.uuid4())
display(HTML(
"""
<div style="border: 1px solid black; width:500px">
<div id="%s" style="background-color:blue; width:0%%"> </div>
</div>
""" % divid)
)
for i in range(1,101):
time.sleep(0.1)
display(Javascript("$('div#%s').width('%i%%')" % (divid, i))) |
This is extremely cool! |
I came across this article : Just for the record of course. A div with a width is perfectly fine with me. :-) |
The code looks good to me and the functionality is fantastic, great job! I'll merge now, but I want to make a suggestion: @minrk, with just adding a tiny bit of explanatory text (a title and a short paragraph before each cell should suffice), your progressbar notebook should really go into the doc examples! It's a great little illustration of how to use the system which I'm sure many people will find useful. I won't delay this PR on that alone, esp. since #1548 depends on this one, so I'll merge now. Great work!! |
clear_output improvements, which allow things like progress bars and other simple animations to work well in the notebook. * `clear_output()` clears the line, even in terminal IPython, the QtConsole and plain Python as well, by printing `\r` to streams. * `clear_output()` avoids the flicker in the notebook by adding a delay, and firing immediately upon the next actual display message. * `display_javascript` hides its `output_area` element, so using display to run a bunch of javascript doesn't result in ever-growing vertical space.
clear_output improvements, which allow things like progress bars and other simple animations to work well in the notebook. * `clear_output()` clears the line, even in terminal IPython, the QtConsole and plain Python as well, by printing `\r` to streams. * `clear_output()` avoids the flicker in the notebook by adding a delay, and firing immediately upon the next actual display message. * `display_javascript` hides its `output_area` element, so using display to run a bunch of javascript doesn't result in ever-growing vertical space.
This was a part of PR #1548, but as I kept finding issues, I decided this should be a separate PR. That PR does depend on this one, and should not be merged before this one.
Changes:
clear_output()
clears the line, even in terminal IPython, the QtConsole and plain Python as well, by printing\r
to streams.clear_output()
avoids the flicker in the notebook by adding a delay, and firing immediately upon the next actual display message.display_javascript
hides itsoutput_area
element, so using display to run a bunch of javascript doesn't result in ever-growing vertical space.