slider = Slider(start=0, end=30, value=0, step=1, title="Smoothing by N Days") slider.on_change('value', callback) doc.add_root(column(slider, plot)) doc.theme = Theme(filename="theme.yaml") # can't use shortcuts here, since we are passing to low level BokehTornado bkapp = Application(FunctionHandler(modify_doc)) bokeh_tornado = BokehTornado({'/bkapp': bkapp}, extra_websocket_origins=["localhost:8000"]) bokeh_http = HTTPServer(bokeh_tornado) # This is so that if this app is run using something like "gunicorn -w 4" then # each process will listen on its own port sockets, port = bind_sockets("localhost", 0) bokeh_http.add_sockets(sockets) @app.route('/', methods=['GET']) def bkapp_page(): script = server_document('http://localhost:%d/bkapp' % port) return render_template("embed.html", script=script, template="Flask") def bk_worker():
async def server_status(request): return JSONResponse({"status": "OK"}) # Bokeh Server configuration and startup: # # To get Gunicorn/Uvicorn's multi-worker # working, we need to create the Bokeh Server # using the low level APIs. Inspired by # https://github.com/bokeh/bokeh/blob/master/examples/howto/server_embed/flask_gunicorn_embed.py bokeh_app = Application(FunctionHandler(bkapp)) bokeh_tornado = BokehTornado( {'/bkapp': bokeh_app}, extra_patterns=[(r'/static_assets/(.*)', StaticFileHandler, { 'path': "static" })], extra_websocket_origins=["localhost:%s" % os.environ["BOKEH_SERVER_PORT"]]) bokeh_http = HTTPServer(bokeh_tornado) bokeh_http.add_socket(socket) bokeh_server = BaseServer(IOLoop.current(), bokeh_tornado, bokeh_http) bokeh_server.start() # Starlette App creation app = Starlette(debug=True, routes=[ Route('/', endpoint=homepage, name='homepage_url'), Mount('/static', StaticFiles(directory='static'),
slider = Slider(start=0, end=30, value=0, step=1, title="Smoothing by N Days") slider.on_change('value', callback) doc.add_root(column(slider, plot)) doc.theme = Theme(filename="theme.yaml") bkapp = Application(FunctionHandler(modify_doc)) bokeh_tornado = BokehTornado({'/bkapp': bkapp}, extra_websocket_origins=["127.0.0.1:8000"]) bokeh_http = HTTPServer(bokeh_tornado) # This is so that if this app is run using something like "gunicorn -w 4" then # each process will listen on its own port sockets, port = bind_sockets("127.0.0.1", 46518) bokeh_http.add_sockets(sockets) @app.route('/', methods=['GET']) def bkapp_page(): print('here') script = server_document('http://127.0.0.1:%d/bkapp' % port) print(str(script)) return render_template("embed.html", script=script, template="Flask")