Flask Bokeh Server on Digital Ocean - Nginx won't render bokeh graphs

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()

Hi,

Are there any relevant log message in the server console output, or in the browser javascript console?

Thanks,

Bryan

···

On Jul 9, 2018, at 12:15, Dennis Graham [email protected] wrote:

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()

You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/faec0ef2-c4cf-41b7-9515-b44520e9811d%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Bryan: The browser javascript console just shows a rendering of the html sent to it. The server console log only shows all my reboots and reloads. Denny

···

On Mon, Jul 9, 2018 at 1:23 PM, Bryan Van de ven [email protected] wrote:

Hi,

Are there any relevant log message in the server console output, or in the browser javascript console?

Thanks,

Bryan

On Jul 9, 2018, at 12:15, Dennis Graham [email protected] wrote:

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](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](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()

You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/faec0ef2-c4cf-41b7-9515-b44520e9811d%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

You received this message because you are subscribed to a topic in the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this topic, visit https://groups.google.com/a/continuum.io/d/topic/bokeh/ZvWTpOtdcP0/unsubscribe.

To unsubscribe from this group and all its topics, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/A43414B5-F68B-44D3-BA61-3CA1ABF6663B%40anaconda.com.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Best Regards
Denny Graham

Hi,

Unfortunately it will be hard to diagnose without more information or being able to reproduce (I don’t have any DO account, and I am traveling this week in any case). There are some debug env vars and command line flags you might try upping. If this was a problem with the WS whitelist I’d expect to see a 403 Forbidden. But maybe it’s not getting that far at all. Glancing at your nginx conf I don’t see anything at all about proxying the web socket connection? That will definitely be necessary. You can see an example config including the parts to make nginx proxy web sockets here:

[https://bokeh.pydata.org/en/latest/docs/user_guide/server.html#nginx](https://bokeh.pydata.org/en/latest/docs/user_guide/server.html#nginx)

It might be profitable to get things running locally behind nginx first, then seeing if applying that same config works on DO.

Thanks,

bryan

···

On Mon, Jul 9, 2018 at 1:23 PM, Bryan Van de ven [email protected] wrote:

Hi,

Are there any relevant log message in the server console output, or in the browser javascript console?

Thanks,

Bryan

On Jul 9, 2018, at 12:15, Dennis Graham [email protected] wrote:

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](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](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()

You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/faec0ef2-c4cf-41b7-9515-b44520e9811d%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

You received this message because you are subscribed to a topic in the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this topic, visit https://groups.google.com/a/continuum.io/d/topic/bokeh/ZvWTpOtdcP0/unsubscribe.

To unsubscribe from this group and all its topics, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/A43414B5-F68B-44D3-BA61-3CA1ABF6663B%40anaconda.com.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Best Regards
Denny Graham

Bryan: Thank you for the suggestions. It helps. I really do not want to resort to two processes. The flask_gunicorn_embed example is the ideal solution if it can be made to work. I will look at the nginx web proxy. I can program in Pytorch with fastai doing embedding, lstm, etc etc but this is kicking my rear at the end of a long project. I will post the code to my github if you want to look at it (new repository called bryan). It’s a great example of using bokeh. The analytical code is in 2.7/Theano so it is kept simple. Cuda tends to make things more complicated than it needs to be. look for
/github.com/dgraham999/bryan

If you want you can use my DO account. I am desperate.
Denny

···

On Mon, Jul 9, 2018 at 1:41 PM, Bryan Van de ven [email protected] wrote:

Hi,

Unfortunately it will be hard to diagnose without more information or being able to reproduce (I don’t have any DO account, and I am traveling this week in any case). There are some debug env vars and command line flags you might try upping. If this was a problem with the WS whitelist I’d expect to see a 403 Forbidden. But maybe it’s not getting that far at all. Glancing at your nginx conf I don’t see anything at all about proxying the web socket connection? That will definitely be necessary. You can see an example config including the parts to make nginx proxy web sockets here:

https://bokeh.pydata.org/en/latest/docs/user_guide/server.html#nginx

It might be profitable to get things running locally behind nginx first, then seeing if applying that same config works on DO.

Thanks,

bryan

On Jul 9, 2018, at 12:33, Dennis Graham [email protected] wrote:

Bryan: The browser javascript console just shows a rendering of the html sent to it. The server console log only shows all my reboots and reloads. Denny

You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/CAEESwy79x4ZdiD6DMtu1d1hBa2RGA1suD36ch3W3LC9e1kTG6Q%40mail.gmail.com.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

You received this message because you are subscribed to a topic in the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this topic, visit https://groups.google.com/a/continuum.io/d/topic/bokeh/ZvWTpOtdcP0/unsubscribe.

To unsubscribe from this group and all its topics, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/5F1E81C8-363C-4AE5-B3E5-EB22120311BC%40anaconda.com.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

On Mon, Jul 9, 2018 at 1:23 PM, Bryan Van de ven [email protected] wrote:

Hi,

Are there any relevant log message in the server console output, or in the browser javascript console?

Thanks,

Bryan

On Jul 9, 2018, at 12:15, Dennis Graham [email protected] wrote:

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](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](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()

You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/faec0ef2-c4cf-41b7-9515-b44520e9811d%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

You received this message because you are subscribed to a topic in the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this topic, visit https://groups.google.com/a/continuum.io/d/topic/bokeh/ZvWTpOtdcP0/unsubscribe.

To unsubscribe from this group and all its topics, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/A43414B5-F68B-44D3-BA61-3CA1ABF6663B%40anaconda.com.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.


Best Regards
Denny Graham

Best Regards
Denny Graham

Hi,

I’m confused, I suggested changes to nginx config because you mention it in the title, said “I just cannot get bokeh to run with Nginx in Flask” and have an nginx config in the OP. I thought I was suggesting changing the configuration of what you are currently doing, not suggesting doing things fundamentally different. If you are running nginx and a bokeh server you are already using two processes. Are you not using nginx?

As I aid I am traveling this week but perhaps I could look at a repo next week when I am back.

Bryan

···

On Mon, Jul 9, 2018 at 1:41 PM, Bryan Van de ven [email protected] wrote:

Hi,

Unfortunately it will be hard to diagnose without more information or being able to reproduce (I don’t have any DO account, and I am traveling this week in any case). There are some debug env vars and command line flags you might try upping. If this was a problem with the WS whitelist I’d expect to see a 403 Forbidden. But maybe it’s not getting that far at all. Glancing at your nginx conf I don’t see anything at all about proxying the web socket connection? That will definitely be necessary. You can see an example config including the parts to make nginx proxy web sockets here:

https://bokeh.pydata.org/en/latest/docs/user_guide/server.html#nginx

It might be profitable to get things running locally behind nginx first, then seeing if applying that same config works on DO.

Thanks,

bryan

On Jul 9, 2018, at 12:33, Dennis Graham [email protected] wrote:

Bryan: The browser javascript console just shows a rendering of the html sent to it. The server console log only shows all my reboots and reloads. Denny

You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/CAEESwy79x4ZdiD6DMtu1d1hBa2RGA1suD36ch3W3LC9e1kTG6Q%40mail.gmail.com.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

You received this message because you are subscribed to a topic in the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this topic, visit https://groups.google.com/a/continuum.io/d/topic/bokeh/ZvWTpOtdcP0/unsubscribe.

To unsubscribe from this group and all its topics, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/5F1E81C8-363C-4AE5-B3E5-EB22120311BC%40anaconda.com.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

On Mon, Jul 9, 2018 at 1:23 PM, Bryan Van de ven [email protected] wrote:

Hi,

Are there any relevant log message in the server console output, or in the browser javascript console?

Thanks,

Bryan

On Jul 9, 2018, at 12:15, Dennis Graham [email protected] wrote:

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](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](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()

You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/faec0ef2-c4cf-41b7-9515-b44520e9811d%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

You received this message because you are subscribed to a topic in the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this topic, visit https://groups.google.com/a/continuum.io/d/topic/bokeh/ZvWTpOtdcP0/unsubscribe.

To unsubscribe from this group and all its topics, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/A43414B5-F68B-44D3-BA61-3CA1ABF6663B%40anaconda.com.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.


Best Regards
Denny Graham

Best Regards
Denny Graham

To be perhaps more clear: If you are behind Nginx, then Nginx will have to be configured to proxy web sockets, full stop. That’s true whether you run “bokeh serve” separately (maybe you thought I was suggesting that?) or whether you embed a bokeh server as a library, e.g. in a flask app as you are doing now. It makes no difference.

Thanks,

Bryan

···

On Mon, Jul 9, 2018 at 1:41 PM, Bryan Van de ven [email protected] wrote:

Hi,

Unfortunately it will be hard to diagnose without more information or being able to reproduce (I don’t have any DO account, and I am traveling this week in any case). There are some debug env vars and command line flags you might try upping. If this was a problem with the WS whitelist I’d expect to see a 403 Forbidden. But maybe it’s not getting that far at all. Glancing at your nginx conf I don’t see anything at all about proxying the web socket connection? That will definitely be necessary. You can see an example config including the parts to make nginx proxy web sockets here:

https://bokeh.pydata.org/en/latest/docs/user_guide/server.html#nginx

It might be profitable to get things running locally behind nginx first, then seeing if applying that same config works on DO.

Thanks,

bryan

On Jul 9, 2018, at 12:33, Dennis Graham [email protected] wrote:

Bryan: The browser javascript console just shows a rendering of the html sent to it. The server console log only shows all my reboots and reloads. Denny

You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/CAEESwy79x4ZdiD6DMtu1d1hBa2RGA1suD36ch3W3LC9e1kTG6Q%40mail.gmail.com.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

You received this message because you are subscribed to a topic in the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this topic, visit https://groups.google.com/a/continuum.io/d/topic/bokeh/ZvWTpOtdcP0/unsubscribe.

To unsubscribe from this group and all its topics, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/5F1E81C8-363C-4AE5-B3E5-EB22120311BC%40anaconda.com.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

On Mon, Jul 9, 2018 at 1:23 PM, Bryan Van de ven [email protected] wrote:

Hi,

Are there any relevant log message in the server console output, or in the browser javascript console?

Thanks,

Bryan

On Jul 9, 2018, at 12:15, Dennis Graham [email protected] wrote:

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](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](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()

You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/faec0ef2-c4cf-41b7-9515-b44520e9811d%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

You received this message because you are subscribed to a topic in the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this topic, visit https://groups.google.com/a/continuum.io/d/topic/bokeh/ZvWTpOtdcP0/unsubscribe.

To unsubscribe from this group and all its topics, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/A43414B5-F68B-44D3-BA61-3CA1ABF6663B%40anaconda.com.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.


Best Regards
Denny Graham

Best Regards
Denny Graham

Bryan: I was just expressing a desire not to run both a bokeh and flask/nginx process. I will post to the github for your convenience. Sorry for the misunderstanding. Denny

···

On Mon, Jul 9, 2018 at 2:17 PM, Bryan Van de ven [email protected] wrote:

To be perhaps more clear: If you are behind Nginx, then Nginx will have to be configured to proxy web sockets, full stop. That’s true whether you run “bokeh serve” separately (maybe you thought I was suggesting that?) or whether you embed a bokeh server as a library, e.g. in a flask app as you are doing now. It makes no difference.

Thanks,

Bryan

On Jul 9, 2018, at 13:15, Bryan Van de ven [email protected] wrote:

Hi,

I’m confused, I suggested changes to nginx config because you mention it in the title, said “I just cannot get bokeh to run with Nginx in Flask” and have an nginx config in the OP. I thought I was suggesting changing the configuration of what you are currently doing, not suggesting doing things fundamentally different. If you are running nginx and a bokeh server you are already using two processes. Are you not using nginx?

As I aid I am traveling this week but perhaps I could look at a repo next week when I am back.

Bryan

On Jul 9, 2018, at 13:01, Dennis Graham [email protected] wrote:

Bryan: Thank you for the suggestions. It helps. I really do not want to resort to two processes. The flask_gunicorn_embed example is the ideal solution if it can be made to work. I will look at the nginx web proxy. I can program in Pytorch with fastai doing embedding, lstm, etc etc but this is kicking my rear at the end of a long project. I will post the code to my github if you want to look at it (new repository called bryan). It’s a great example of using bokeh. The analytical code is in 2.7/Theano so it is kept simple. Cuda tends to make things more complicated than it needs to be. look for
/github.com/dgraham999/bryan

If you want you can use my DO account. I am desperate.
Denny

You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/CAEESwy6J7iapDNHmcYWHX-d15mp8qGnHTfA0U-sfLQ4kEHFKGQ%40mail.gmail.com.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

You received this message because you are subscribed to a topic in the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this topic, visit https://groups.google.com/a/continuum.io/d/topic/bokeh/ZvWTpOtdcP0/unsubscribe.

To unsubscribe from this group and all its topics, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/B53E1215-C163-4C07-9D61-546F94BF32B2%40anaconda.com.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

On Mon, Jul 9, 2018 at 1:41 PM, Bryan Van de ven [email protected] wrote:

Hi,

Unfortunately it will be hard to diagnose without more information or being able to reproduce (I don’t have any DO account, and I am traveling this week in any case). There are some debug env vars and command line flags you might try upping. If this was a problem with the WS whitelist I’d expect to see a 403 Forbidden. But maybe it’s not getting that far at all. Glancing at your nginx conf I don’t see anything at all about proxying the web socket connection? That will definitely be necessary. You can see an example config including the parts to make nginx proxy web sockets here:

https://bokeh.pydata.org/en/latest/docs/user_guide/server.html#nginx

It might be profitable to get things running locally behind nginx first, then seeing if applying that same config works on DO.

Thanks,

bryan

On Jul 9, 2018, at 12:33, Dennis Graham [email protected] wrote:

Bryan: The browser javascript console just shows a rendering of the html sent to it. The server console log only shows all my reboots and reloads. Denny

You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/CAEESwy79x4ZdiD6DMtu1d1hBa2RGA1suD36ch3W3LC9e1kTG6Q%40mail.gmail.com.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

You received this message because you are subscribed to a topic in the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this topic, visit https://groups.google.com/a/continuum.io/d/topic/bokeh/ZvWTpOtdcP0/unsubscribe.

To unsubscribe from this group and all its topics, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/5F1E81C8-363C-4AE5-B3E5-EB22120311BC%40anaconda.com.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.


Best Regards
Denny Graham

On Mon, Jul 9, 2018 at 1:23 PM, Bryan Van de ven [email protected] wrote:

Hi,

Are there any relevant log message in the server console output, or in the browser javascript console?

Thanks,

Bryan

On Jul 9, 2018, at 12:15, Dennis Graham [email protected] wrote:

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](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](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()

You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/faec0ef2-c4cf-41b7-9515-b44520e9811d%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

You received this message because you are subscribed to a topic in the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this topic, visit https://groups.google.com/a/continuum.io/d/topic/bokeh/ZvWTpOtdcP0/unsubscribe.

To unsubscribe from this group and all its topics, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/A43414B5-F68B-44D3-BA61-3CA1ABF6663B%40anaconda.com.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.


Best Regards
Denny Graham

Best Regards
Denny Graham

Hi Dennis,

Were you ever able to figure this out? I’m stuck with the exact same issue and am just about ready to give up but have invested so many hours into trying to get this configured correctly.

I tried looking at the repo you reference above but it seems to be gone.

Cheers,
Alberto

···

On Monday, July 9, 2018 at 3:54:37 PM UTC-5, Dennis Graham wrote:

Bryan: I was just expressing a desire not to run both a bokeh and flask/nginx process. I will post to the github for your convenience. Sorry for the misunderstanding. Denny

On Mon, Jul 9, 2018 at 2:17 PM, Bryan Van de ven [email protected] wrote:

To be perhaps more clear: If you are behind Nginx, then Nginx will have to be configured to proxy web sockets, full stop. That’s true whether you run “bokeh serve” separately (maybe you thought I was suggesting that?) or whether you embed a bokeh server as a library, e.g. in a flask app as you are doing now. It makes no difference.

Thanks,

Bryan

On Jul 9, 2018, at 13:15, Bryan Van de ven [email protected] wrote:

Hi,

I’m confused, I suggested changes to nginx config because you mention it in the title, said “I just cannot get bokeh to run with Nginx in Flask” and have an nginx config in the OP. I thought I was suggesting changing the configuration of what you are currently doing, not suggesting doing things fundamentally different. If you are running nginx and a bokeh server you are already using two processes. Are you not using nginx?

As I aid I am traveling this week but perhaps I could look at a repo next week when I am back.

Bryan

On Jul 9, 2018, at 13:01, Dennis Graham [email protected] wrote:

Bryan: Thank you for the suggestions. It helps. I really do not want to resort to two processes. The flask_gunicorn_embed example is the ideal solution if it can be made to work. I will look at the nginx web proxy. I can program in Pytorch with fastai doing embedding, lstm, etc etc but this is kicking my rear at the end of a long project. I will post the code to my github if you want to look at it (new repository called bryan). It’s a great example of using bokeh. The analytical code is in 2.7/Theano so it is kept simple. Cuda tends to make things more complicated than it needs to be. look for
/github.com/dgraham999/bryan

If you want you can use my DO account. I am desperate.
Denny

On Mon, Jul 9, 2018 at 1:41 PM, Bryan Van de ven [email protected] wrote:

Hi,

Unfortunately it will be hard to diagnose without more information or being able to reproduce (I don’t have any DO account, and I am traveling this week in any case). There are some debug env vars and command line flags you might try upping. If this was a problem with the WS whitelist I’d expect to see a 403 Forbidden. But maybe it’s not getting that far at all. Glancing at your nginx conf I don’t see anything at all about proxying the web socket connection? That will definitely be necessary. You can see an example config including the parts to make nginx proxy web sockets here:

[https://bokeh.pydata.org/en/latest/docs/user_guide/server.html#nginx](https://bokeh.pydata.org/en/latest/docs/user_guide/server.html#nginx)

It might be profitable to get things running locally behind nginx first, then seeing if applying that same config works on DO.

Thanks,

bryan

On Jul 9, 2018, at 12:33, Dennis Graham [email protected] wrote:

Bryan: The browser javascript console just shows a rendering of the html sent to it. The server console log only shows all my reboots and reloads. Denny

On Mon, Jul 9, 2018 at 1:23 PM, Bryan Van de ven [email protected] wrote:

Hi,

Are there any relevant log message in the server console output, or in the browser javascript console?

Thanks,

Bryan

On Jul 9, 2018, at 12:15, Dennis Graham [email protected] wrote:

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](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](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()

You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/faec0ef2-c4cf-41b7-9515-b44520e9811d%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

You received this message because you are subscribed to a topic in the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this topic, visit https://groups.google.com/a/continuum.io/d/topic/bokeh/ZvWTpOtdcP0/unsubscribe.

To unsubscribe from this group and all its topics, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/A43414B5-F68B-44D3-BA61-3CA1ABF6663B%40anaconda.com.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.


Best Regards
Denny Graham

You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/CAEESwy79x4ZdiD6DMtu1d1hBa2RGA1suD36ch3W3LC9e1kTG6Q%40mail.gmail.com.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

You received this message because you are subscribed to a topic in the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this topic, visit https://groups.google.com/a/continuum.io/d/topic/bokeh/ZvWTpOtdcP0/unsubscribe.

To unsubscribe from this group and all its topics, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/5F1E81C8-363C-4AE5-B3E5-EB22120311BC%40anaconda.com.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.


Best Regards
Denny Graham

You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/CAEESwy6J7iapDNHmcYWHX-d15mp8qGnHTfA0U-sfLQ4kEHFKGQ%40mail.gmail.com.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

You received this message because you are subscribed to a topic in the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this topic, visit https://groups.google.com/a/continuum.io/d/topic/bokeh/ZvWTpOtdcP0/unsubscribe.

To unsubscribe from this group and all its topics, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/B53E1215-C163-4C07-9D61-546F94BF32B2%40anaconda.com.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.


Best Regards
Denny Graham

Alberto,

No. I gave up on Nginx and just brought it online without it using Gunicorn. See brtfld.com. I have been taking an Nginx online course to try and find a solution. Dennis Graham

···

Best Regards
Denny Graham