Refresh results in Google Colaboratory as the page loads

假如想象 提交于 2019-12-11 18:25:43

问题


I am working on google colab as it a part of my school project.

But I got stuck on a problem. So, I wanted some one to help me out.

I want that every time the page is refreshed, a new random number generated using python gets shown up in the output area (in the image it has number 1). I am able to run a javascript code as soon as the page loads. But I don't know how to simulate a click on the run icon. So, if someone knows how to simulate click on that run button (it's actually not a button, it's a <div>). Please, if anyone could help me out, I will be very thankful.

Sorry for poor english.

Code:

from random import randint
import IPython
print(randint(1,5))
js_code = '''
document.addEventListener("load", a());
function a() {
  var s = /* The run button */
  s.cick();
}
'''
display(IPython.display.Javascript(js_code));

回答1:


By design, Colab requires user interaction to execute code. There's no way to automatically execute a cell when a notebook loads.



来源:https://stackoverflow.com/questions/55918385/refresh-results-in-google-colaboratory-as-the-page-loads

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!