散景组件通过 jquery.success 渲染

Bokeh components render through jquery.success

我正在尝试将组件传递回 jQuery.ajax 调用,然后设置 html。

散景代码:

layout = column(plot)
script, div = components(layout)
res_json = jsonify(dict(script=script, div=div))
return res_json, 200, {'Content-Type': 'application/json'}

Jquery

success: function(data) {
  $("#bokeh_script").html(data["script"]);
  $("#bokeh_div").html(data["div"]);
}

但我收到此错误:

我已经阅读了一些资料,似乎所有内容的加载顺序都有问题。我也很好奇你是否可以传递像 .html(<script>) 这样的标签并让它仍然加载?谢谢。

对于散景,渲染顺序很重要,因此 ajax 调用必须在脚本之前渲染 div:

success(function(data){
    $("#bokeh_div").html(data["div"]);
    $("head").append(data["script"]);
});