Greetings, as per the title I’m not seeing expected output in the Output widget when I use the context manager. If I use the append_stdout method instead, it does work (however that doesn’t seem to work for my use case, where I want to append a display() object, and append_display_data method seems not to be implemented yet).
I would guess append_stdout() is method of out so that it isn’t compatible with appending to print-sourced things? However, then why does it work if you follow the append with print()?:
out = widgets.Output(layout={'border':'1px solid black'})
out.append_stdout("bar")
with out:
for _ in range(10):
print("foo")
display(out)
I’ve learned not to rely on print() in conjunction with ipywidgets, unless it is in a function wrapped by the decorator @out.capture(clear_output=True,wait=True), but it is clearly discussed as if viable in the documentation.
This works:
import ipywidgets as widgets
out = widgets.Output(layout={'border':'1px solid black'})
with out:
for _ in range(10):
out.append_stdout("foo\n")
out.append_stdout("bar")
display(out)
For those looking to replicate, here’s some other code versions:
import ipywidgets as widgets
out = widgets.Output(layout={'border':'1px solid black'})
with out:
for _ in range(10):
print("foo")
out
And
import ipywidgets as widgets
out = widgets.Output(layout={'border':'1px solid black'})
with out:
for _ in range(10):
print("foo")
out.append_stdout("bar")
out
Your environment where it doesn’t work seems to have a mix of super up-to-date, such as jupyter core & ipywidgets, and somewhat out of date things, such as IPython, ipykernel, & traitlets. For comparison a recent build and launch via MyBinder using a requirements.txt:
I was hoping one of those might fix it. It is odd. There are a number of open issues involving the output context manager at the ipywidgets issues page. However, I’m not seeing one that exactly matches yours at this time. If you file an issue there I would focus on that one in the documentation and show what you see vs the expected.