简体   繁体   English

在页面加载时刷新Google Colaboratory的结果

[英]Refresh results in Google Colaboratory as the page loads

在此输入图像描述

I am working on google colab as it a part of my school project. 我正在研究谷歌colab,因为它是我学校项目的一部分。

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). 我希望每次刷新页面时,使用python生成的新随机数会显示在输出区域中(在图像中它的编号为1)。 I am able to run a javascript code as soon as the page loads. 我可以在页面加载后立即运行javascript代码。 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> ). 所以,如果有人知道如何模拟点击该运行按钮(它实际上不是一个按钮,它是一个<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));

By design, Colab requires user interaction to execute code. 通过设计,Colab需要用户交互来执行代码。 There's no way to automatically execute a cell when a notebook loads. 当笔记本加载时,无法自动执行单元格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM