要保存Bokeh仪表板并将其作为独立的HTML文件运行,可以使用以下步骤:
bokeh.embed.file_html()
函数将仪表板对象转换为HTML字符串。以下是一个示例代码:
from bokeh.plotting import figure, show
from bokeh.io import output_file
def create_dashboard():
# 创建Bokeh绘图
p = figure()
p.line([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], line_width=2)
# 返回仪表板对象
return p
# 创建仪表板对象
dashboard = create_dashboard()
# 输出到HTML文件
output_file("dashboard.html")
html = file_html(dashboard, CDN, "My Dashboard")
with open("dashboard.html", "w") as file:
file.write(html)
在上面的示例中,create_dashboard()
函数创建了一个简单的Bokeh绘图,并返回该绘图对象。然后,我们使用bokeh.embed.file_html()
函数将该绘图对象转换为HTML字符串。最后,我们将HTML字符串保存到名为"dashboard.html"的文件中。
这样,您就可以通过在浏览器中打开"dashboard.html"文件来独立运行Bokeh仪表板,并查看其中的所有数据。
上一篇:保存Bokeh小部件的动态值
下一篇:保存不带格式的XML