Python 保存Bokeh dashdoard(独立)和内部生成的所有数据

Python 保存Bokeh dashdoard(独立)和内部生成的所有数据,python,bokeh,dashboard,Python,Bokeh,Dashboard,编辑Bokeh dashboard后是否有保存它的方法 例如,我加载了我的仪表板,创建了一些绘图并保存了它们(最后一个选项卡)。然后我想将我的“进度”保存到.html文件中,这样我就不必在每次初始化脚本后都再次执行所有这些操作 这是我的仪表板的屏幕截图: 谢谢大家! 因此,解决方案是: 1将bokeh文档(整个仪表板)转换为.json并作为文件下载 例如,您可以通过单击按钮来执行此操作 # creating button download_json = Button(label="Downl

编辑Bokeh dashboard后是否有保存它的方法

例如,我加载了我的仪表板,创建了一些绘图并保存了它们(最后一个选项卡)。然后我想将我的“进度”保存到.html文件中,这样我就不必在每次初始化脚本后都再次执行所有这些操作

这是我的仪表板的屏幕截图:

谢谢大家!

因此,解决方案是:
1
将bokeh文档(整个仪表板)转换为.json并作为文件下载

例如,您可以通过单击按钮来执行此操作

#  creating button
download_json = Button(label="Download json", width=70)
# callback
download_json_func = CustomJS(args=dict(source=source_fill_groupby),code="""
function saveText(text, filename){
var a = document.createElement('a');
a.setAttribute('href', 'data:text/plain;charset=utf-8,'+encodeURIComponent(text));
a.setAttribute('download', filename);
a.click()
}
var obj = Bokeh.documents[0].to_json_string();
saveText( JSON.stringify(obj), "filename.json" );
""")
# assigning callback to the button
download_json.js_on_event(ButtonClick, download_json_func)
2
下载文件后,需要将其还原到Jupyter笔记本的下一个单元格中。假设应该有一个FileInput小部件,这样我们就可以上传我们的文件,并且它会出现在div块中

from bokeh.models.widgets import FileInput
# creating div where our saved dashboard will be shown
div = Div(text='<div id="document-container"></div>', width=500, height=500)
# adding widget
l = FileInput(accept='.json')
# callback
l.js_on_change('value', CustomJS(code="""\
const {Document} = Bokeh.require('document/document');
// uploaded .json-file  
const data = JSON.parse(atob(cb_obj.value));            
const doc = Document.from_json_string(data);
// dashboard to show
Bokeh.embed.add_document_standalone(doc, document.getElementById('document-container'), [], true);                                     
cb_obj.disabled = true;
"""))

show(column(l, div))

你想只看一眼,还是想继续工作?你的截图看起来像是使用了一个Jupyter笔记本——你是否使用了Bokeh的Python代码,还是所有的东西都使用JavaScript?它完全基于js。我在Jupyter笔记本中使用它,而不启动服务器。我希望能够使用它之后,添加一些新的图表或进行另一个数据查询。所以,我想它必须是html格式的。正如我所发现的,在对.html文件进行更新后保存该文件不会更改源文件。我尝试以.html格式下载仪表板,然后在浏览器中打开,进行更改,然后将其保存到硬盘中。在那之后,我得到了与第一步下载的文件相同的文件。这意味着在对仪表板进行更改后将其保存在.html中是不起作用的。我必须找到另一个解决方案。是的,HTML文件只存储布局。所有其他状态都存储在JavaScript内存中。我正在尝试想出一个解决方案-这应该是可能的。好吧,可以使用
Bokeh.documents[0]保存文档。将文档保存到\u json\u string()
并使用
Bokeh.embed.add\u document\u standalone
加载它。但在我的情况下,情节没有呈现任何东西。
    l.js_on_change('value', CustomJS(code="""
function b64DecodeUnicode(str) {
    // Going backwards: from bytestream, to percent-encoding, to original string.
    return decodeURIComponent(atob(str).split('').map(function(c) {
        return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
    }).join(''));
}

const {Document} = Bokeh.require('document/document');
const data = JSON.parse(b64DecodeUnicode(cb_obj.value));
const doc = Document.from_json_string(data);
Bokeh.embed.add_document_standalone(doc, document.getElementById('document-container1'), [], true);
cb_obj.disabled = true;
"""))