页面加载时刷新Google合作实验室的结果 [英] Refresh results in Google Colaboratory as the page loads

查看:67
本文介绍了页面加载时刷新Google合作实验室的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究Google colab,因为这是我学校项目的一部分.

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.

我希望每次刷新页面时,使用python生成的新随机数都会显示在输出区域中(在图像中为1).页面加载后,我就能运行javascript代码.但是我不知道如何模拟运行图标上的点击.因此,如果有人知道如何模拟该运行按钮(实际上不是按钮,则是< div> ).请,如果有人可以帮助我,我将非常感激.

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.

对不起,英语不好.

代码:

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

推荐答案

根据设计,Colab需要用户交互才能执行代码.笔记本加载时无法自动执行单元.

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

这篇关于页面加载时刷新Google合作实验室的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆