1

recently I read the following code from https://docs.bokeh.org/en/latest/docs/user_guide/tools.html#custom-tooltip.

from bokeh.plotting import ColumnDataSource, figure, output_file, show

output_file("toolbar.html")
source = ColumnDataSource(data=dict(
x=[1, 2, 3, 4, 5],
y=[2, 5, 8, 2, 7],
desc=['A', 'b', 'C', 'd', 'E'],
imgs=[
    'https://docs.bokeh.org/static/snake.jpg',
    'https://docs.bokeh.org/static/snake2.png',
    'https://docs.bokeh.org/static/snake3D.png',
    'https://docs.bokeh.org/static/snake4_TheRevenge.png',
    'https://docs.bokeh.org/static/snakebite.jpg'
],
fonts=[
    '<i>italics</i>',
    '<pre>pre</pre>',
    '<b>bold</b>',
    '<small>small</small>',
    '<del>del</del>'
]
))
TOOLTIPS = """
<div>
    <div>
        <img
            src="@imgs" height="42" alt="@imgs" width="42"
            style="float: left; margin: 0px 15px 15px 0px;"
            border="2"
        ></img>
    </div>
    <div>
        <span style="font-size: 17px; font-weight: bold;">@desc</span>
        <span style="font-size: 15px; color: #966;">[$index]</span>
    </div>
    <div>
        <span>@fonts{safe}</span>
    </div>
    <div>
        <span style="font-size: 15px;">Location</span>
        <span style="font-size: 10px; color: #696;">($x, $y)</span>
    </div>
</div>
"""
p = figure(width=400, height=400, tooltips=TOOLTIPS,
       title="Mouse over the dots")

p.circle('x', 'y', size=20, source=source)

show(p)

It plots some circles and when I point the mouse over a circle the image related is shown. As you can see from the code, the images are taken from the web. This code generates a standalone HTML file. I tried to replaced these images with other ones present in local disk. So I inserted the name of the files in imags = []. The code generates the standalone HTML file and the images are shown only if the HTML and the images are in the same directory. My question at this point is: Is there a way to incorporate these images directly in the standalone HTML? So if I decide to share this file, an other user can view these images on the graph (without sharing the entire directory)

dj8030
  • 21
  • 2
  • Take a look at the last few lines of this page http://windsolarhybridaustralia.x10.mx/httpoutputtools-tutorial.html then find the base 64 routines for python and look up embedding base 64 images in html pages. – Samuel Marchant Oct 23 '21 at 10:14

0 Answers0