bokeh與tornado結合的三種方式

1 bokeh生成一個html文件,由tornado來不斷的去執行bokeh後生成新的html文件後,再去返回新的html

我之前用過這種方式,下面的鏈接也是這樣方式

https://stackoverflow.com/questions/24985038/display-bokeh-generated-file-using-tornado

2 bokeh作爲一個tornado的一個應用端的庫來使用

Embedding Bokeh Server as a Library

from bokeh.server.server import Server
server = Server(
    bokeh_applications,  # list of Bokeh applications
    io_loop=loop,        # Tornado IOLoop
    **server_kwargs      # port, num_procs, etc.
)

# start timers and services and immediately return
server.start()

3 tornado作爲一個bokeh的客戶端來使用

from flask import Flask, render_template

from bokeh.client import pull_session
from bokeh.embed import server_session

app = Flask(__name__)

@app.route('/', methods=['GET'])
def bkapp_page():

    with pull_session(url="http://localhost:5006/sliders") as session:

        # update or customize that session
        session.document.roots[0].children[1].title.text = "Special Sliders For A Specific User!"

        # generate a script to load the customized session
        script = server_session(session_id=session.id, url='http://localhost:5006/sliders')

        # use the script in the rendered page
        return render_template("embed.html", script=script, template="Flask")

if __name__ == '__main__':
    app.run(port=8080)

注意:

倘若生成可以交互的方式的服務端的話,最好還是用bokeh serve 這種原生的方式

與tornado結合的方式更多的是爲了展示數據使用。

另外,如果是實時流數據話,也是最好用bokeh serve原生的方式

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章