在bokeh服务器上创建绘图,然后下载客户端

xcitsw88  于 2021-09-29  发布在  Java
关注(0)|答案(0)|浏览(204)

正如标题所示,我目前有一个运行在dataiku中的bokeh webapp,它创建并显示一个绘图。我希望能够添加一个下载按钮,将html文件从服务器端发送到客户端(即下载绘图的html)。
我见过有人用csv文件和excel文件来管理它
https://discourse.bokeh.org/t/how-to-download-a-datatable-as-a-csv-in-a-bokeh-server-app/1150/6
将文件从服务器发送到bokeh上的客户端
不幸的是,我不知道任何js,所以我不知道如何调整它以输出html文件。下面有一些代码试图显示我当前的位置,但我知道输出文件和保存被忽略了。

import numpy as np
from bokeh.io import curdoc, output_file
from bokeh.layouts import column
from bokeh.models import ColumnDataSource, Button
from bokeh.plotting import figure

# Set up data

N = 200
x = np.linspace(0, 4*np.pi, N)
y = np.sin(x)
source = ColumnDataSource(data=dict(x=x, y=y))

# Set up plot

plot = figure(plot_height=400, plot_width=400, title="my sine wave",
              tools="crosshair,pan,reset,save,wheel_zoom",
              x_range=[0, 4*np.pi], y_range=[-2.5, 2.5], name='my_plot')

plot.line('x', 'y', source=source, line_width=3, line_alpha=0.6)

def download():
    my_plot = curdoc().get_model_by_name('my_plot')
    output_file('myplot.html')
    save(my_plot)

download_button = Button(label="Download plot", width=100, button_type="success")
download_button.on_click(download)

curdoc().add_root(column(plot, download_button))

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题