8

In my Bokeh server based project I have to use/add a few images that are within the Bokeh project folder. I created a static folder called "static/" within the project folder and basically my code looks like this:

  div_img_html = "<img src='static/image.png'>"
  div_img = Div(text = div_img_html)

however when running the server I get:

  404 GET /static/image.png (::1) 2.00ms

Obviously Bokeh gets the Div command however server doesn't know how to retrieve the actual file.... The actual file certainly is residing within that folder.

Thank you in advance for any suggestions and hopefully for a solution!

Andrei Damian
  • 101
  • 1
  • 4
  • Did my response below not answer your question? If so, can you clarify what other information you need? – bigreddot Jan 11 '18 at 02:12

1 Answers1

6

For directory format apps, static subdirectories are per-app. That is, the static route is relative to app (and any --prefix as well). E.g. for an app in a directory myapp:

bokeh serve --show myapp

that has contains static/image.png, then the correct code would be

from bokeh.models import Div
from bokeh.io import curdoc

div = Div(text="<img src='myapp/static/foo.png'>")

curdoc().add_root(div)

It's possible some kind of template option could be added to provide this path more easily. I'd encourage you to file a feature request on the GitHub issue tracker.

bigreddot
  • 33,642
  • 5
  • 69
  • 122
  • This helps with static images, thanks. But where should I put my `favicon.ico` so `bokeh serve myapp` will render it? – gepcel Dec 01 '17 at 04:50
  • You'll have to use an HTML template with the favicon specified explicitly I think. See e.g. https://github.com/bokeh/bokeh/tree/master/examples/app/crossfilter which uses a template for the page. – bigreddot Dec 01 '17 at 15:22