As the title suggests, I currently have a bokeh webapp that runs in Dataiku, it creates and displays a plot. What I'd like to be able to do is add a download button that sends the HTML file from the server side to the client side (i.e. downloads the HTML of the plot).
I've seen people have managed this with a csv file and an excel file
- https://discourse.bokeh.org/t/how-to-download-a-datatable-as-a-csv-in-a-bokeh-server-app/1150/6
- send file from server to client on bokeh
Unfortunately I don't know any JS so I'm not sure how to adapt this to output an HTML file. I have some code below trying to display where I'm currently at but I know that output_file and save are just being ignored.
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))