问题描述
在基于Bokeh服务器的项目中,我必须使用/添加Bokeh项目文件夹中的一些图像.我在项目文件夹中创建了一个名为"static/"的静态文件夹,基本上我的代码如下所示:
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
很明显,Bokeh收到了Div命令,但是服务器不知道如何检索实际文件....实际文件肯定位于该文件夹中.
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!
推荐答案
对于目录格式应用,静态子目录是每个应用.也就是说,static
路由是相对于应用程序(以及任何--prefix
)的路由.例如.对于目录myapp
中的应用程序:
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
包含static/image.png
,则正确的代码应为
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)
有可能可以添加某种模板选项以更轻松地提供此路径.我建议您在 GitHub问题跟踪器上提交功能请求.
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.
这篇关于如何使用Div在Bokeh中显示静态图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!