Jupyter notebook 从jupyter笔记本中获取互动滑块,以便在bokeh html文件中工作
你好,这是我的第一个问题(我什么都不知道),我有点紧张,不想让你紧张 我的总体目标是创建一个30分钟的课程(部分),让学生可以看到:Jupyter notebook 从jupyter笔记本中获取互动滑块,以便在bokeh html文件中工作,jupyter-notebook,slider,bokeh,Jupyter Notebook,Slider,Bokeh,你好,这是我的第一个问题(我什么都不知道),我有点紧张,不想让你紧张 我的总体目标是创建一个30分钟的课程(部分),让学生可以看到: 交互式图形和超级芬西代码 被吸引成为软件工程师,或者至少开始阅读代码。(我来衡量影响) 为此,我认为Jupyter笔记本是最好的武器。出于可用性原因和不同层次的交互性,我开始考虑创建html文件以进行远程访问(在允许我在学校环境中安装更多内容之前,我的管理员会杀了我) 所以我看到了: from bokeh.plotting import figure fr
- 交互式图形和超级芬西代码
- 被吸引成为软件工程师,或者至少开始阅读代码。(我来衡量影响)
from bokeh.plotting import figure
from bokeh.resources import CDN
from bokeh.embed import file_html
plot = figure()
plot.circle([1,2], [3,4])
html = file_html(plot, CDN, "my plot")
要从bokeh图形创建html
但是如何在这个独立的html文件中获得好的交互滑块
那么,如何(即使是无意义的)将其转换为:
变成这样:
谢谢你的评论。sry我的英语不如外表看起来那么好,但我不如外表看起来那么聪明我知道没有任何简单的方法可以通过Jupyter Interactions在独立的HTML中实现这一点。但是,您可以使用Bokeh自己的小部件生成独立输出来实现这一点:
Bokeh 2.0将允许Jupyter Interactions与Bokeh服务器应用程序一起工作(而不是独立输出)。据我所知,没有任何简单的方法可以让Jupyter Interactions在独立HTML中工作。但是,您可以使用Bokeh自己的小部件生成独立输出来实现这一点: Bokeh2.0将允许Jupyter交互程序与Bokeh服务器应用程序(而不是独立输出)一起工作,这是一些正在进行的工作
from ipywidgets import interact
import numpy as np
from bokeh.io import push_notebook, show, output_notebook
from bokeh.plotting import figure
output_notebook()
In [ ]:
x = np.linspace(0, 2*np.pi, 2000)
y = np.sin(x)
In [ ]:
p = figure(title="simple line example", plot_height=300, plot_width=600, y_range=(-5,5))
r = p.line(x, y, color="#2222aa", line_width=3)
In [ ]:
def update(f, w=1, A=1, phi=0):
if f == "sin": func = np.sin
elif f == "cos": func = np.cos
elif f == "tan": func = np.tan
r.data_source.data['y'] = A * func(w * x + phi)
push_notebook()
In [ ]:
show(p, notebook_handle=True)
In [ ]:
interact(update, f=["sin", "cos", "tan"], w=(0,100), A=(1,5), phi=(0, 20, 0.1))