I’m trying to capture the output of a few objects and then display them inside an HBox.
In the following example, I’m expecting to see the headers printed side by side.
from IPython.display import display_html, DisplayObject
from ipywidgets import HBox, Output
from IPython.utils import capture
class Foo:
def _ipython_display_(self):
display_html('<h2>header</h2>', raw=True)
objects = [Foo(), Foo(), Foo()]
with capture.capture_output() as cap:
for o in objects:
o._ipython_display_()
items = []
for captured in cap.outputs:
out = Output()
out.append_display_data(DisplayObject(data=captured.data, metadata=captured.metadata))
items.append(out)
display(HBox(items))
Actual output in jupyter:
HBox(children=(Output(outputs=({'output_type': 'display_data', 'data': {'text/plain': '<IPython.core.display.D…