# Why does the Output context manager not show the desired output?

**URL:** https://discourse.jupyter.org/t/why-does-the-output-context-manager-not-show-the-desired-output/13926
**Category:** Widgets
**Created:** [April 19, 2022, 4:29pm UTC](https://discourse.jupyter.org/t/why-does-the-output-context-manager-not-show-the-desired-output/13926 "2022-04-19T16:29:56Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Andrei\_Cristea](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/andrei_cristea/32/6976_2.png) [@Andrei\_Cristea](https://discourse.jupyter.org/u/Andrei_Cristea)
#### Post date: [April 19, 2022, 4:29pm UTC](https://discourse.jupyter.org/t/why-does-the-output-context-manager-not-show-the-desired-output/13926/1 "2022-04-19T16:29:56Z")

</div>

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

My jupyter version:

```auto
>jupyter --version
Selected Jupyter core packages...
IPython : 7.18.1
ipykernel : 5.3.4
ipywidgets : 7.7.0
jupyter_client : 7.2.2
jupyter_core : 4.10.0
jupyter_server : not installed
jupyterlab : 2.2.6
nbclient : not installed
nbconvert : 5.6.1
nbformat : 5.0.7
notebook : 6.1.1
qtconsole : 5.3.0
traitlets : 4.3.3

```

Attaching screenshot below rather than pasting code, as it includes execution times:

 ![image](https://canada1.discourse-cdn.com/flex031/uploads/jupyter/original/2X/8/87c56ec6a6ce9e22621f9b71671aba5e1546c7b3.png)

Thank you!

---

<div class="post-metadata">

### Author: ![fomightez](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/fomightez/32/495_2.png) [@fomightez](https://discourse.jupyter.org/u/fomightez)
#### Post date: [April 19, 2022, 6:48pm UTC](https://discourse.jupyter.org/t/why-does-the-output-context-manager-not-show-the-desired-output/13926/2 "2022-04-19T18:48:01Z")

</div>

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()`?:

```python
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](https://ipywidgets.readthedocs.io/en/latest/examples/Output%20Widget.html).

* * *

This works:

```python
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)

```

Somewhat based on [here](https://github.com/jupyter-widgets/ipywidgets/issues/2385)

* * *

For those looking to replicate, here’s some other code versions:

```auto
import ipywidgets as widgets
out = widgets.Output(layout={'border':'1px solid black'})
with out:
    for _ in range(10):
        print("foo")
out

```

And

```auto
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

```

---

<div class="post-metadata">

### Author: ![Andrei\_Cristea](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/andrei_cristea/32/6976_2.png) [@Andrei\_Cristea](https://discourse.jupyter.org/u/Andrei_Cristea)
#### Post date: [April 19, 2022, 7:48pm UTC](https://discourse.jupyter.org/t/why-does-the-output-context-manager-not-show-the-desired-output/13926/3 "2022-04-19T19:48:57Z")

</div>

Right, basically this example from [the documentation](https://ipywidgets.readthedocs.io/en/latest/examples/Output%20Widget.html) doesn’t work for me in the environment I pasted above:

```auto
with out:
    for i in range(10):
        print(i, 'Hello world!')

```

That same snippet **does** work fine on another machine with this environment:

```auto
>jupyter --version
jupyter core : 4.6.3
jupyter-notebook : 6.0.3
qtconsole : 4.3.1
ipython : 6.4.0
ipykernel : 4.8.2
jupyter client : 6.1.5
jupyter lab : 0.32.1
nbconvert : 6.0.7
ipywidgets : 7.2.1
nbformat : 5.1.3
traitlets : 4.3.2

```

 ![image](https://canada1.discourse-cdn.com/flex031/uploads/jupyter/original/2X/5/5896277bf566135b0defe389c2cc576c73a1f732.png)

For simplicity I’ve put the two setups side-by-side.

> | | Works fine | Doesn’t work |
> | --- | --- | --- |
> | jupyter core | 4.6.3 | 4.10.0 |
> | jupyter-notebook | 6.0.3 | 6.1.1 |
> | qtconsole | 4.3.1 | 5.3.0 |
> | ipython | 6.4.0 | 7.18.1 |
> | ipykernel | 4.8.2 | 5.3.4 |
> | jupyter client | 6.1.5 | 7.2.2 |
> | jupyter lab | 0.32.1 | 2.2.6 |
> | nbconvert | 6.0.7 | 5.6.1 |
> | ipywidgets | 7.2.1 | 7.7.0 |
> | nbformat | 5.1.3 | 5.0.7 |
> | traitlets | 4.3.2 | 4.3.3 |

---

<div class="post-metadata">

### Author: ![fomightez](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/fomightez/32/495_2.png) [@fomightez](https://discourse.jupyter.org/u/fomightez)
#### Post date: [April 20, 2022, 3:26am UTC](https://discourse.jupyter.org/t/why-does-the-output-context-manager-not-show-the-desired-output/13926/4 "2022-04-20T03:26:27Z")

</div>

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`:

 ![run_w_specs](https://canada1.discourse-cdn.com/flex031/uploads/jupyter/original/2X/7/73b073b1bc87598b29d564dc34b70ba93783f12c.png)

And a build that originated today:

 ![more_recent_example_Spec](https://canada1.discourse-cdn.com/flex031/uploads/jupyter/original/2X/c/cb838c8b6674cb1936aa206dc34b53b6ca61c750.png)

---

<div class="post-metadata">

### Author: ![Andrei\_Cristea](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/andrei_cristea/32/6976_2.png) [@Andrei\_Cristea](https://discourse.jupyter.org/u/Andrei_Cristea)
#### Post date: [April 20, 2022, 1:46pm UTC](https://discourse.jupyter.org/t/why-does-the-output-context-manager-not-show-the-desired-output/13926/5 "2022-04-20T13:46:26Z")

</div>

I tried upgrading all the packages via `$ pip install -U _packagename_` and it didn’t resolve the issue. New package list:

```auto
>jupyter --version
Selected Jupyter core packages...
IPython : 7.32.0
ipykernel : 6.13.0
ipywidgets : 7.7.0
jupyter_client : 7.2.2
jupyter_core : 4.10.0
jupyter_server : not installed
jupyterlab : 2.2.6
nbclient : 0.6.0
nbconvert : 6.5.0
nbformat : 5.3.0
notebook : 6.4.11
qtconsole : 5.3.0
traitlets : 5.1.1

```

---

<div class="post-metadata">

### Author: ![fomightez](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/fomightez/32/495_2.png) [@fomightez](https://discourse.jupyter.org/u/fomightez)
#### Post date: [April 20, 2022, 2:42pm UTC](https://discourse.jupyter.org/t/why-does-the-output-context-manager-not-show-the-desired-output/13926/6 "2022-04-20T14:42:59Z")

</div>

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](https://github.com/jupyter-widgets/ipywidgets/issues). 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.

---

<div class="post-metadata">

### Author: ![felix](https://avatars.discourse-cdn.com/v4/letter/f/aeb1de/32.png) [@felix](https://discourse.jupyter.org/u/felix)
#### Post date: [May 2, 2022, 5:53am UTC](https://discourse.jupyter.org/t/why-does-the-output-context-manager-not-show-the-desired-output/13926/7 "2022-05-02T05:53:03Z")

</div>

I’m running into something similar:

This works fine:  
 ![Screenshot from 2022-05-02 11-14-45](https://canada1.discourse-cdn.com/flex031/uploads/jupyter/original/2X/4/4c098836e3e6d2ecc4930fecd4d508e1a660461a.png)

This doesn’t:

```auto
import ipywidgets as widgets
with widgets.Output():
    widgets.IntSlider()

```

Doesn’t display the widget. Assigning the output widget to a variable and doing a display(out) as well doesn’t work.

```auto
jupyter --version

Selected Jupyter core packages...
IPython : 8.0.1
ipykernel : 6.8.0
ipywidgets : 7.6.5
jupyter_client : 7.1.2
jupyter_core : 4.9.1
jupyter_server : 1.13.5
jupyterlab : not installed
nbclient : 0.5.10
nbconvert : 6.4.1
nbformat : 5.1.3
notebook : 6.4.8
qtconsole : not installed
traitlets : 5.1.1

```

I’m trying to create a Voila Dashboard and was planing to use ipywidgets, but with this issue, I’m afraid that wouldn’t be possible.
