Replies: 5 comments 5 replies
-
It seems jupyter-widgets/ipywidgets#2617 is pretty messy... |
Beta Was this translation helpful? Give feedback.
-
I was thinking a screenshot-based approach might be more successful. Option 1: html2canvas as in: https://github.com/msjgriffiths/jupyter-shot/blob/master/jupyter-shot.ipynb Option 1 if you're more comfortable with JS ... you can start with my PR. I got it working once but can't reproduce LOL. Option 2 if you want to keep it pure Python. iframes have always felt messy to me ... but I'm not a web-developer. As long as it works, and is fully automated I think it's fine. |
Beta Was this translation helpful? Give feedback.
-
okay after playing around with https://ipywidgets.readthedocs.io/en/latest/embedding.html#python-interface |
Beta Was this translation helpful? Give feedback.
-
Not super elegant but another option on the table along these lines: import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from PIL import Image
driver = webdriver.Firefox()
driver.get('http://localhost:8910/notebooks/evoked_tutorial.ipynb?token=e1b5af1b39680df1bcd5f887ae1626fd2282332c9929dd0c')
actions = ActionChains(driver)
time.sleep(5.)
actions.key_down(Keys.SHIFT).key_down(Keys.ENTER).key_up(
Keys.SHIFT).key_up(Keys.ENTER).perform()
time.sleep(10.)
element = driver.find_element_by_xpath(
'//div[@class="p-Widget p-Panel jupyter-widgets widget-container widget-gridbox"]')
location = element.location
size = element.size
actions.move_to_element(element).perform()
driver.save_screenshot("shot.png")
x = location['x']
y = location['y']
w = size['width']
h = size['height']
width = x + w
height = y + h
im = Image.open('shot.png')
im = im.crop((int(x), int(y), int(width), int(height)))
im.show() |
Beta Was this translation helpful? Give feedback.
-
I figured out the reason why Will Basically we need something that can "pause" the execution of cells without blocking the kernel. |
Beta Was this translation helpful? Give feedback.
-
I found a way to freeze and show GUI snapshots:
embed_minimal_html
fromipywidgets.embed
)IFrame
fromIPython.display
)But here are some deficits in this approach, which I'm trying to address and would like to share to see you have any ideas:
src
attribute in the<iframe>
tosrcdoc
as the latter does not support cross-domain requests, while the embedded html content requires JS scripts.embed_minimal_html
is not good at capturingOutput
widget.Output
,embed_minimal_html
won't store the style.Output
widget,embed_minimal_html
won't store the content.embed_minimal_html
correctly stores everything.Beta Was this translation helpful? Give feedback.
All reactions