Anyone who can help: I have invested untold hours in figuring out neural networks for forecasting (i.e., even Howard’s fastai). I used Bokeh for interactive displays. When working just beatiful. I just cannot get bokeh to run with Nginx in Flask.
When the py file with flask and bokeh is run in the virtualenv being started with a gunicorn and wsgi command line it works perfectly. This is the command line return.
'$ gunicorn --bind 165.227.zzz.xxx:8000 wsgi:app
[2018-07-09 18:40:42 +0000] [2549] [INFO] Starting gunicorn 19.9.0
[2018-07-09 18:40:42 +0000] [2549] [INFO] Listening at: http://165.227.21.248:8000 (2549)
[2018-07-09 18:40:42 +0000] [2549] [INFO] Using worker: sync
[2018-07-09 18:40:42 +0000] [2552] [INFO] Booting worker with pid: 2552
I then create these config files after deactivating the virtualenv. The html files display but without the bokeh graphs. I really need some help.
The systemd service file:
[Unit]
Description=Gunicorn instance to serve bf
After=network.target
[Service]
User=dennis
Group=www-data
WorkingDirectory=/home/dennis/bf
Environment=“PATH=/home/dennis/bf/brtfld/bin”
ExecStart=/home/dennis/bf/brtfld/bin/gunicorn --workers 3 --bind unix:bf.sock -m 007 wsgi:app
[Install]
WantedBy=multi-user.target
the wsgi.py file:
from bfg import app
if name == “main”:
app.run()
the nginx config.
server {
listen 80;
server_name 165.127.xxx.xxx;
location / {
include proxy_params;
proxy_pass http://unix:/home/dennis/bf/bf.sock;
}
}
and finally the .py file driving the flask and bokeh rendering.
if name == ‘main’:
import sys
sys.exit()
app = Flask(name)
#bokeh function
def modify_doc_compare(doc):
fs = CompareDisplay()
layout = fs.compare()
doc.add_root(layout)
cls = Application(FunctionHandler(modify_doc_cls))
ptch = Application(FunctionHandler(modify_doc_ptr_chg))
plt = Application(FunctionHandler(modify_doc_plot))
pplt = Application(FunctionHandler(modify_doc_partner_plot))
fa = Application(FunctionHandler(modify_doc_featall))
fi = Application(FunctionHandler(modify_doc_featid))
nn = Application(FunctionHandler(modify_doc_compare))
sockets, port = bind_sockets(“165.227.xxx.xxx”, 0)
@app.route(’/’,methods=[‘GET’])
@app.route(’/land’,methods=[‘GET’])
def land():
return render_template('land.html')
@app.route(’/lstm’, methods=[‘GET’])
def lstm():
script = server_document('http://165.227.xxx.xxx:%d/lstm' %port)
return render_template("lstm.html", script=script,template="Flask")
@app.route(’/embed’, methods=[‘GET’])
def embed():
script = server_document('http://165.227.xxx.xxx:%d/embed' %port)
return render_template("embed.html", script=script,template="Flask")
def bk_worker():
asyncio.set_event_loop(asyncio.new_event_loop())
bokeh_tornado = BokehTornado({’/class’:cls,’/ptrchg’:ptch,’/plot’:plt,’/partnerplot’:pplt,’/featall’:fa,’/featid’:fi,’/lstm’:nn,’/embed’:nn}, extra_websocket_origins=[“165.227.xxx.xxx:8000”])
bokeh_http = HTTPServer(bokeh_tornado)
bokeh_http.add_sockets(sockets)
server = BaseServer(IOLoop.current(), bokeh_tornado, bokeh_http)
server.start()
server.io_loop.start()
from threading import Thread
Thread(target=bk_worker).start()

