Hi all,
I am trying to show the output from the jupyter notebook which is shown with print() or display() functions.
The sample code is below. I would like to show cap
with panel.
from IPython.utils import capture
def test():
print(1)
with capture.capture_output() as cap:
test()
cap.show()
Any suggestions?
In the case of capturing display(image), I got the solution by using panel.pane.PNG
.
from PIL import Image
import requests
import IPython
import io
from IPython.utils import capture
def test():
url = 'https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png'
im = Image.open(requests.get(url, stream=True).raw)
display(im)
with capture.capture_output() as cap:
test()
image = cap.outputs[0].data['image/png']
img = Image.open(io.BytesIO(image))
import panel as pn
pn.extension()
pn.pane.PNG(img)