Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Export SVG does not show Div elements and creating random temp files #14159

Open
PrateekArya opened this issue Nov 19, 2024 · 3 comments
Open
Labels

Comments

@PrateekArya
Copy link

Software versions

Python version: 3.10.14
Bokeh version: 3.6.1
IPython version: 8.29.0

Browser name and version

ChromeDriver 131.0.6778.69

Jupyter notebook / Jupyter Lab version

No response

Expected behavior

The Div text should be shown in the exported SVG file and no random temporary files should be created!

Observed behavior

Exporting Bokeh layout or gridplot to SVG does not show Div elements. Moreover, the code generates a new temporary html files (with a random name) in the working directory every time the code is executed even when I have specified an output_file name. If output_file name is specified, then the temporary file creation is skipped at the first execution.

Example code

import numpy as np

from bokeh.plotting import figure, output_file
from bokeh.models import Div
import bokeh.layouts as layouts
from bokeh.io import export_svg

N = 10000

x = np.random.normal(0, np.pi, N)
y = np.sin(x) + np.random.normal(0, 0.2, N)

TOOLS = "pan,wheel_zoom,box_zoom,reset,save,box_select"

p = figure(tools=TOOLS, output_backend="svg")
p.scatter(x, y, alpha=0.1, nonselection_alpha=0.001)

div = Div(text='Plotting random')

fig = layouts.column(div, p)

output_file('testSVG.html')

export_svg(fig, filename='testSVG.svg')

Stack traceback or browser console output

No response

Screenshots

No response

@PrateekArya PrateekArya changed the title [BUG] Export SVG does not show Div elements and unnecessary temp files [BUG] Export SVG does not show Div elements and creating random temp files Nov 19, 2024
@mattpap
Copy link
Contributor

mattpap commented Dec 15, 2024

Exporting Bokeh layout or gridplot to SVG does not show Div elements.

Bokeh is only able to export plots and layouts of plots as images, in particular as SVG. There is no generic way to export arbitrary HTML (like a Div) to SVG.

@bryevdv
Copy link
Member

bryevdv commented Dec 19, 2024

This seems like it should be closed noaction?

Edit: elaborating, the use of temp files in the current dir is expected and intentional to work around selenium issues:

# XXX: selenium has issues with /tmp directory (or equivalent), so try using the
# current directory first, if writable, and otherwise fall back to the system
# default tmp directory.

The only thing I could see doing here is try to clean up more thoroughly.

@PrateekArya
Copy link
Author

PrateekArya commented Dec 20, 2024

Regarding the Div elements, I recommend that the user gets a warning or error saying that it is not possible to show Div elements in exported SVG files. Otherwise, it looks like a bug. The users can then think about using a workaround, for instance, creating empty figures with headings and text, if they really want to export to SVG. 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants