I cannot export svg files because the process is stuck trying to load the file from temporary file that is stored in this path:
file:///C:\Users\UserName\AppData\Local\Temp\bokehkh29timo.html
This problem happens with the environment variables: BOKEH_RESOURCES=server-dev
and BOKEH_RESOURCES=server
. The bokeh script url looks OK in the temp file:
http://localhost:5006/static/js/bokeh.min.js
The bokeh.min.js
script is loaded fine when I place the url in the browser. But when I export the svg and the html file is created in the temp folder, the script url cannot be loaded anymore.
The instruction when the stops the execution is this one
web_driver.get("file:///" + tmp.path)
With BOKEH_RESOURCES=cdn
or BOKEH_RESOURCES=inline
(value by default) works well.
Is this wrong or it works as expected? Am I missing anything? Is there a way to change the resources dynamically just to export them with the inline bokeh script and workaround this?
from os import environ
if 'BOKEH_RESOURCES' in environ:
print('BOKEH RESOURCES: {}'.format(environ['BOKEH_RESOURCES']))
import numpy as np
from bokeh.plotting import figure
from bokeh.io import curdoc, export_svgs
from bokeh.models import Button
from bokeh.layouts import column
N = 10
x = np.random.random(size=N) * 10
y = np.random.random(size=N) * 10
radii = np.random.random(size=N) * 1.5
p = figure(
x_axis_label='X axis',
y_axis_label='Y axis',
title='Random plot',
tools="crosshair,pan,wheel_zoom,reset,save",
output_backend = 'webgl',
)
p.scatter(
x=x,
y=y,
radius=radii,
fill_color='red',
fill_alpha=0.6,
line_color=None
)
def export_svg_file():
print('Exporting plot.svg...')
p.output_backend = "svg"
export_svgs(p, filename="plot.svg")
# p.output_backend = "webgl"
bt = Button(
label="Export SVG",
button_type="success",
width=50
)
bt.on_click(export_svg_file)
curdoc().add_root(column(children=[bt, p]))