I'm trying to run a server on a remote location to render a plot with circles so that the tooltip includes an image of the item hovered on.
I'm using Bokeh 3.3.0 and tornado. This is my code:
from bokeh.layouts import column
from bokeh.models import ColumnDataSource,HoverTool
from bokeh.plotting import figure
from bokeh.server.server import Server
def bkapp(doc):
#get necessary data...
dfsource=ColumnDataSource(df)
hover = HoverTool(tooltips ="""
<div>
<div>
<img
src="@_id.png"
style="float: left; margin: 0px 5px 5px 0px;"
border="2"
></img>
</div>
<div>
<span style="font-size: 15px;">@_id</span>
<span style="font-size: 10px; color: #696;">(@ucx, @ucy)</span>
</div>
""")
# create a plot
p = figure(sizing_mode="stretch_width", max_width=2000, height=800,
tools=["pan", 'wheel_zoom',"tap","reset"])
p.add_tools(hover)
circle = p.circle(source=dfsource,x="ucx",y="ucy")
doc.add_root(p)
server = Server({'/': bkapp}, num_procs=4)
server.start()
if __name__ == '__main__':
print('Opening Bokeh application on http://localhost:5006/')
server.io_loop.add_callback(server.show, "/")
server.io_loop.start()
The plot works as intended but the images are not accessible.
The folder structure is simple:
-cwd
--myapp.py
--imagefolder/
I have tried setting src as:
src="imagefolder/@_id.png"src="file://@_id.png"src="http://localhost:5006/@_id.png"
and other combinations but I think the problem is that the folder is not being served. Can someone tell me how can I tell tornado, through the Bokeh API to please serve this folder of images so that I can do something like http://localhost:5006/imagefolder/_id.png and be able to see the image?
So I basically endedup embedding a bokeh app in a flask app, which is not elegant at all and speaks for the poor idea if mixing server programming and visualization both in bokeh. But any ways this is the idea:
there is more info here github.com/realpython/flask-bokeh-example and here bokeh user guide