This is a follow up of my previous question.
The structure of the files is shown below. I have to run the scripts using python -m bokeh_module.bokeh_sub_module
from the top directory
.
├── other_module
│ ├── __init__.py
│ └── other_sub_module.py
├── bokeh_module
│ ├── __init__.py
│ ├── image.png # not showing
│ └── bokeh_sub_module.py
└── image.png # not showing either
The bokeh_sub_module.py is using the standalone bokeh server. However the image will not show no matter where it is placed. Is there something I missed? Thank you for any help.
from other_module import other_sub_module
import os
from bokeh.server.server import Server
from bokeh.layouts import column
from bokeh.plotting import figure, show
def make_document(doc):
def update():
pass
# do something with other_sub_module
p = figure(match_aspect=True)
p.image_url( ['file://'+os.path.join(os.path.dirname(__file__), 'image.png')], 0, 0, 1, 1)
doc.add_root(column(p, sizing_mode='stretch_both'))
doc.add_periodic_callback(callback=update, period_milliseconds=1000)
apps = {'/': make_document}
server = Server(apps)
server.start()
server.io_loop.add_callback(server.show, "/")
server.io_loop.start()
Using file://
for the URL is not going to work in general. It could only possibly work if the browser viewing the app is running on the same server that is running the Bokeh server app. Even then I think there may be browser security policies that prohibit loading images from local URLs on to an HTML canvas. Realistically, the image URL needs to refer to an actual http://
or https://
URL. If you could use a directory-style Bokeh app then you could put the image in a static
subdirectory, and Bokeh would automatically serve the image for you. But since you mention having to run the app by executing a module with an embedded Bokeh Server
, I think your two options are:
BokehTornado
instance configured with StaticFileHandler
to serve the images, and pass that as the extra_patterns
argument to Server
http
or https
URLs.