如何更换curdoc [英] How to replace curdoc

查看:56
本文介绍了如何更换curdoc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在bokeh服务器应用程序中替换当前文档?

How can I replace the current document in a bokeh server app?

我有一个以前的文档另存为 json_string .如果我这样做

I have a previous document saved as a json_string. If I do

set_curdoc(Document.from_json_string(json_string))

这似乎可以正确更改curdoc(),但是新文档不会显示在浏览器中.

this seems to properly change curdoc(), however the new document is not displayed in the browser.

推荐答案

我找到了一种解决方法,其他地方建议更新现有布局的子级,而不是更新整个curdoc().

I found a workaround, other places suggest to update the children of an existing layout instead of updating the whole curdoc().

我这样做了,但是我需要扩展一点以从保存在json字符串中的文档中做到这一点.

I did that but I had to expand a bit to do that from a document saved in a json string.

我不得不将所有模型的 document 属性从导入的文档切换到curdoc()(否则,它会抱怨这些模型属于另一个文档)

I had to switch the document attribute of all the models from the imported document to curdoc() instead (otherwise it complains that the models belong to another document)

假设我导入的文档和当前文档都只有一个根:

assuming that the document I import and the current document both have only one root:

new_doc = Document.from_json_string(json_string)

new_grid_models = collect_models(new_doc.roots[0])

for elem in new_grid_models:
    try:
        elem.document = curdoc()
    except AttributeError:
        elem._document = curdoc()

new_children = new_doc.roots[0].children
del new_doc

grid.children = new_children

之后,需要将python回调重新影响到适当的导入模型.

After that the python callbacks need to be re-affected to the appropriate imported models.

我在这里提出了一个示例应用程序:在Bitbucket上保存并加载应用

I put up an example app here: save_and_load app on Bitbucket

这篇关于如何更换curdoc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆