How to make Bokeh work with a REST api backend instead of bokeh-serve?

限于喜欢 提交于 2019-12-23 05:19:18

问题


How can I make Bokeh work with my own REST api backend using CustomJS instead of bokeh-serve? components() do not seem to render inputs and inputs seem to come always with a need to run bokeh-serve.


回答1:


Barnabas, it is basically impossible to diagnose a problem if you do not provide actual code and describe in extreme detail what you have already tried. FWIW here is a minimal script that renders a Bokeh Button in a Flask app:

import flask

from bokeh.embed import components
from bokeh.core.templates import FILE
from bokeh.models.widgets import Button
from bokeh.resources import INLINE
from bokeh.util.string import encode_utf8

app = flask.Flask(__name__)

@app.route("/")
def foo():
    button = Button(label="test")

    script, div = components(button, INLINE)
    html = FILE.render(
        plot_script=script,
        plot_div=div,
        bokeh_js=INLINE.render_js(),
        bokeh_css=INLINE.render_css(),
    )
    return encode_utf8(html)

app.run(debug=True)

There are things I'd certainly do different in a real deployment (no INLINE resources, e.g) but without additional information about your actual use-case or what you are really wanting to do it is impossible to offer additional guidance.




回答2:


It turns out that to use widgets one needs to include extra js and css to the html page.
In my case those are

  • bokeh-0.11.1.min.js,
  • bokeh-widgets-0.11.1.min.js
  • bokeh-compiler-0.11.1.min.js and
  • bokeh-widgets-0.11.1.min.css.


来源:https://stackoverflow.com/questions/36630308/how-to-make-bokeh-work-with-a-rest-api-backend-instead-of-bokeh-serve

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!