我注意到交互式小部件在我的 Jupyter Lab 笔记本中不起作用。
以下代码应生成交互式滑块,但不会:
from ipywidgets import interact, interactive, fixed, interact_manual
import ipywidgets as widgets
def f(x):
return x
interact(f, x=10);
Run Code Online (Sandbox Code Playgroud)
这里有什么问题,我怎样才能让小部件工作?
我在 kubernetes 上的 jupyterhub 中运行 jupyterlab。
我正在尝试使用例如显示小部件
from ipywidgets import interact
@interact(x=(0, 100, 10))
def p(x=50):
pass
Run Code Online (Sandbox Code Playgroud)
实验室笔记本打印的不是预期的交互式小部件:
interactive(children=(IntSlider(value=50, description='x', step=10), Output()), _dom_classes=('widget-interact...
Run Code Online (Sandbox Code Playgroud)
检查 javascript 控制台时:
default.js:129 Error: Object 'jupyter.widget' not found in registry
at default.js:1474
at new Promise (<anonymous>)
at Object.loadObject (default.js:1453)
at DefaultKernel.<anonymous> (default.js:919)
at Generator.next (<anonymous>)
at default.js:9
at new Promise (<anonymous>)
at push.YC29.__awaiter (default.js:5)
at DefaultKernel._handleCommOpen (default.js:911)
at DefaultKernel.<anonymous> (default.js:1018)
Run Code Online (Sandbox Code Playgroud)
我尝试了许多不同的组合:
!pip install ipywidgets
!pip install widgetsnbextension --upgrade
!pip install widgetslabextension --upgrade
!conda install -n base …Run Code Online (Sandbox Code Playgroud) google.colab.output.eval_js有什么方法可以获取Jupyter Notebook 中的行为吗?我有一些代码用来IPython.display让用户绘制图像。当按下按钮时,JS 将图像内容保存为data,然后我data = eval_js("data")在 Python 中使用该内容将该内容提取到 Python 中。我正在尝试在 Jupyter Notebook 中复制这种行为。我把完整的代码放在下面。
from IPython.display import HTML, Image
from google.colab.output import eval_js
canvas_html = """
<canvas width=%d height=%d style="background-color:rgb(240,240,240)"=></canvas>
<button>Guess Number</button>
<script>
var canvas = document.querySelector('canvas')
var ctx = canvas.getContext('2d')
ctx.lineWidth = %d
var button = document.querySelector('button')
var mouse = {x: 0, y: 0}
canvas.addEventListener('mousemove', function(e) {
mouse.x = e.pageX - this.offsetLeft
mouse.y = e.pageY - this.offsetTop
})
canvas.onmousedown = ()=>{
ctx.beginPath()
ctx.moveTo(mouse.x, …Run Code Online (Sandbox Code Playgroud)