python - Select DropDown无法使用JS回调更改ColumnDataSource

标签 python bokeh

我尝试更改多个参数(参数),但这不起作用。

Bokeh 版本是1.3.4。

from bokeh.layouts import column
from bokeh.layouts import column
from bokeh.models import CustomJS, ColumnDataSource, Slider, Select
from bokeh.plotting import Figure, output_notebook, show
import numpy as np
a = 20


bokeh_tools = "pan,wheel_zoom"

output_notebook()
plot_2s = ColumnDataSource(data=dict(x=[1, 2, 3], y=[1, 2, 3]))
plot_3s = ColumnDataSource(data=dict(x=[3, 4, 5], y=[1, 2, 3]))
line_source = ColumnDataSource(data=dict(x=[1, 2, 3], y=[1, 2, 3]))

plot_1 = figure(x_axis_type="datetime", plot_width=800, tools=bokeh_tools, title="plot_1")
plot_1.line(x = 'x', y='y', source=plot_2s)
plot_2 = figure(x_axis_type="datetime", plot_width=800, tools=bokeh_tools, title="plot_2")
plot_2.line(x='x', y='y', source=line_source)

select = Select(title="SELECT", options=["val1", "val2"])
column = column(select, plot_2)
show(column)

select.callback = CustomJS(args={"cds2": plot_2s, "cds3": plot_3s, "ls": line_source}, code="""
         if(cb_obj.value === "val1"){ 
                 ls.data = cds2.data;
         }else if(cb_obj.value === "val2"){
                 ls.data = cds3.data;
         }
         ls.change.emit();
         """)

没有回调未实现的错误消息

最佳答案

您的回调永远不会执行,因为它永远不会添加到输出中。一旦您调用 show,就会生成并显示 HTML 输出。该点之后的任何操作实际上都是无操作,并且就输出而言不存在。通常 show 应最后调用。

关于python - Select DropDown无法使用JS回调更改ColumnDataSource,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57566344/

相关文章:

python - 制作石头、剪刀、布游戏

python - 如何将 pandas 系列转换为 seaborn 条形图

html - Bokeh - 如何让悬停工具仅适用于特定点?

python - 如何旋转 Bokeh 图中的箭头标记以显示风速方向?

python - 如何使用静态变量、自定义 getter 和 setter 扩展 SWIG 中的结构?

python - listAPI View 中以十为基数的int()的文字无效 djangorest框架

python - 将 HTML 颜色名称转换为十六进制

python - Heroku 运行 Bokeh 服务器——H12 超时

python-3.x - Python Bokeh 文件输入小部件

python - 如何重载 * 参数解包运算符?