Bokeh server on Heroku with proxying

Hi,

First, I want to say what a wonderful tool Bokeh is. Now, my question. I have set up a small Flask app on a Heroku web dyno that connects to a Bokeh server instance running on a worker dyno. I use Honcho to allow me to run both processes on a single (free) dyno. The Flask app connects to the bokeh server with:

@app.route(’/plot’)
def interactive():
session = pull_session(session_id=None, url=‘http://localhost:5006/script/’)

tag = autoload_server(next(iter(session.document.roots)), session_id=session.id,
                       app_path='/script')
session.close()

return render_template('interactive_app.html', tag=tag)

Here “script” is the name of the script launched with “bokeh serve”. The whole setup works fine on my local setup (with accept-origin set correctly for local use), however, when run through Heroku the pull_session call looks for a bokeh server instance on my host machine, which makes some sense. I was wondering if anyone has any suggestions on how to correctly proxy the pull_session call to connect to the bokeh server running on the remote worker dyno? I fear my web-application knowledge is rather lacking.

I am currently using bokeh version 0.11.1.

Hi Matt,

Unfortunately I don't have any experience with Heroku, but in case it is useful there is some information about setting up a Bokeh server behind an (Nginx) proxy here:

  Bokeh server — Bokeh 3.3.2 Documentation

Note that if the Bokeh server and the Flask server doing the autoload_server are on different machines, then you will also need to add --extra-websocket-origin to tell the Bokeh server to accept websocket connections from the Flask server machine (it sounds like you have everything on one VM tho).

Bryan

···

On Mar 1, 2016, at 5:35 AM, [email protected] wrote:

Hi,

First, I want to say what a wonderful tool Bokeh is. Now, my question. I have set up a small Flask app on a Heroku web dyno that connects to a Bokeh server instance running on a worker dyno. I use Honcho to allow me to run both processes on a single (free) dyno. The Flask app connects to the bokeh server with:

@app.route('/plot')
def interactive():
    session = pull_session(session_id=None, url='http://localhost:5006/script/'\)

    tag = autoload_server(next(iter(session.document.roots)), session_id=session.id,
                           app_path='/script')
    session.close()
    
    return render_template('interactive_app.html', tag=tag)

Here "script" is the name of the script launched with "bokeh serve". The whole setup works fine on my local setup (with accept-origin set correctly for local use), however, when run through Heroku the pull_session call looks for a bokeh server instance on my host machine, which makes some sense. I was wondering if anyone has any suggestions on how to correctly proxy the pull_session call to connect to the bokeh server running on the remote worker dyno? I fear my web-application knowledge is rather lacking.

I am currently using bokeh version 0.11.1.

--
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/067d1821-5939-4b21-94fb-85e46a8ec46d%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Hi,

Only web dynos get http requests:
https://devcenter.heroku.com/articles/dynos#dyno-configurations

So the Bokeh server will need to be on a web dyno (probably a separate Heroku app from the Flask server).

This feature idea would give you a good alternative perhaps (avoiding the separate Flask):
https://github.com/bokeh/bokeh/issues/3962

Incidentally that’s a very manageable feature for a new contributor to add I think, if anyone on the list is looking for an extremely useful contribution!

Havoc

···

On Tue, Mar 1, 2016 at 6:35 AM, [email protected] wrote:

Hi,

First, I want to say what a wonderful tool Bokeh is. Now, my question. I have set up a small Flask app on a Heroku web dyno that connects to a Bokeh server instance running on a worker dyno. I use Honcho to allow me to run both processes on a single (free) dyno. The Flask app connects to the bokeh server with:

@app.route(‘/plot’)
def interactive():
session = pull_session(session_id=None, url=‘http://localhost:5006/script/’)

tag = autoload_server(next(iter(session.document.roots)), session_id=[session.id](http://session.id),
                       app_path='/script')
session.close()

return render_template('interactive_app.html', tag=tag)

Here “script” is the name of the script launched with “bokeh serve”. The whole setup works fine on my local setup (with accept-origin set correctly for local use), however, when run through Heroku the pull_session call looks for a bokeh server instance on my host machine, which makes some sense. I was wondering if anyone has any suggestions on how to correctly proxy the pull_session call to connect to the bokeh server running on the remote worker dyno? I fear my web-application knowledge is rather lacking.

I am currently using bokeh version 0.11.1.

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/067d1821-5939-4b21-94fb-85e46a8ec46d%40continuum.io.

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

Havoc Pennington

Senior Software Architect

Hi Bryan

Thank you for your response, the nginx functions are extremely helpful. I’ve managed to get the system up and running by splitting the flask app and bokeh server onto two separate app instances, using the allow-origin to ensure the system works. I’d be happy to share a code skeleton if you think it would be useful. Essentially, the bokeh server needs to be started with the $PORT Heroku variable and the pull_session performed on port 80.

The output from autoload_server, i.e. “tag”, has http://localhost:5006/, automatically written in by default and I needed to do a str.replace() operation add the correct hostname.

···

On Thursday, 3 March 2016 19:25:38 UTC+2, Bryan Van de ven wrote:

Hi Matt,

Unfortunately I don’t have any experience with Heroku, but in case it is useful there is some information about setting up a Bokeh server behind an (Nginx) proxy here:

    [http://bokeh.pydata.org/en/latest/docs/user_guide/server.html#reverse-proxying-with-nginx](http://bokeh.pydata.org/en/latest/docs/user_guide/server.html#reverse-proxying-with-nginx)

Note that if the Bokeh server and the Flask server doing the autoload_server are on different machines, then you will also need to add --extra-websocket-origin to tell the Bokeh server to accept websocket connections from the Flask server machine (it sounds like you have everything on one VM tho).

Bryan

On Mar 1, 2016, at 5:35 AM, [email protected] wrote:

Hi,

First, I want to say what a wonderful tool Bokeh is. Now, my question. I have set up a small Flask app on a Heroku web dyno that connects to a Bokeh server instance running on a worker dyno. I use Honcho to allow me to run both processes on a single (free) dyno. The Flask app connects to the bokeh server with:

@app.route(‘/plot’)

def interactive():

session = pull_session(session_id=None, url='[http://localhost:5006/script/](http://localhost:5006/script/)')
tag = autoload_server(next(iter(session.document.roots)), session_id=[session.id](http://session.id),
                       app_path='/script')
session.close()
return render_template('interactive_app.html', tag=tag)

Here “script” is the name of the script launched with “bokeh serve”. The whole setup works fine on my local setup (with accept-origin set correctly for local use), however, when run through Heroku the pull_session call looks for a bokeh server instance on my host machine, which makes some sense. I was wondering if anyone has any suggestions on how to correctly proxy the pull_session call to connect to the bokeh server running on the remote worker dyno? I fear my web-application knowledge is rather lacking.

I am currently using bokeh version 0.11.1.


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/067d1821-5939-4b21-94fb-85e46a8ec46d%40continuum.io.

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

Hi Havoc

Thanks for the message. I was writing a response to Bryan just as your message came through. Basically, I had to run each component on a separate Heroku instance.

  • Matt
···

On Tuesday, 1 March 2016 14:21:29 UTC+2, Matt Adendorff wrote:

Hi,

First, I want to say what a wonderful tool Bokeh is. Now, my question. I have set up a small Flask app on a Heroku web dyno that connects to a Bokeh server instance running on a worker dyno. I use Honcho to allow me to run both processes on a single (free) dyno. The Flask app connects to the bokeh server with:

@app.route(‘/plot’)
def interactive():
session = pull_session(session_id=None, url=‘http://localhost:5006/script/’)

tag = autoload_server(next(iter(session.document.roots)), session_id=[session.id](http://session.id),
                       app_path='/script')
session.close()

return render_template('interactive_app.html', tag=tag)

Here “script” is the name of the script launched with “bokeh serve”. The whole setup works fine on my local setup (with accept-origin set correctly for local use), however, when run through Heroku the pull_session call looks for a bokeh server instance on my host machine, which makes some sense. I was wondering if anyone has any suggestions on how to correctly proxy the pull_session call to connect to the bokeh server running on the remote worker dyno? I fear my web-application knowledge is rather lacking.

I am currently using bokeh version 0.11.1.

Hey Matthew,

A Heroku template or HOWTO would be immensely helpful and deeply appreciated!

Thanks,

Peter

···

On Friday, March 4, 2016, [email protected] wrote:

Hi Bryan

Thank you for your response, the nginx functions are extremely helpful. I’ve managed to get the system up and running by splitting the flask app and bokeh server onto two separate app instances, using the allow-origin to ensure the system works. I’d be happy to share a code skeleton if you think it would be useful. Essentially, the bokeh server needs to be started with the $PORT Heroku variable and the pull_session performed on port 80.

The output from autoload_server, i.e. “tag”, has http://localhost:5006/, automatically written in by default and I needed to do a str.replace() operation add the correct hostname.

On Thursday, 3 March 2016 19:25:38 UTC+2, Bryan Van de ven wrote:

Hi Matt,

Unfortunately I don’t have any experience with Heroku, but in case it is useful there is some information about setting up a Bokeh server behind an (Nginx) proxy here:

    [http://bokeh.pydata.org/en/latest/docs/user_guide/server.html#reverse-proxying-with-nginx](http://bokeh.pydata.org/en/latest/docs/user_guide/server.html#reverse-proxying-with-nginx)

Note that if the Bokeh server and the Flask server doing the autoload_server are on different machines, then you will also need to add --extra-websocket-origin to tell the Bokeh server to accept websocket connections from the Flask server machine (it sounds like you have everything on one VM tho).

Bryan

On Mar 1, 2016, at 5:35 AM, [email protected] wrote:

Hi,

First, I want to say what a wonderful tool Bokeh is. Now, my question. I have set up a small Flask app on a Heroku web dyno that connects to a Bokeh server instance running on a worker dyno. I use Honcho to allow me to run both processes on a single (free) dyno. The Flask app connects to the bokeh server with:

@app.route(‘/plot’)

def interactive():

session = pull_session(session_id=None, url='[http://localhost:5006/script/](http://localhost:5006/script/)')
tag = autoload_server(next(iter(session.document.roots)), session_id=[session.id](http://session.id),
                       app_path='/script')
session.close()
return render_template('interactive_app.html', tag=tag)

Here “script” is the name of the script launched with “bokeh serve”. The whole setup works fine on my local setup (with accept-origin set correctly for local use), however, when run through Heroku the pull_session call looks for a bokeh server instance on my host machine, which makes some sense. I was wondering if anyone has any suggestions on how to correctly proxy the pull_session call to connect to the bokeh server running on the remote worker dyno? I fear my web-application knowledge is rather lacking.

I am currently using bokeh version 0.11.1.


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/067d1821-5939-4b21-94fb-85e46a8ec46d%40continuum.io.

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

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/9ab807e3-75d7-4e63-8add-1cce193ecb8e%40continuum.io.

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


Peter Wang

CTO, Co-founder

Seconded, that would be extremely welcome. Is there some easy way to package things up in to a "one button deploy"? I feel like I have seen that sort of thing, if so that would be an amazing addition to help others get started as quickly as possible.

Bryan

···

On Mar 4, 2016, at 9:08 AM, Peter Wang <[email protected]> wrote:

Hey Matthew,

A Heroku template or HOWTO would be immensely helpful and deeply appreciated!

Thanks,
Peter

On Friday, March 4, 2016, <[email protected]> wrote:
Hi Bryan

Thank you for your response, the nginx functions are extremely helpful. I've managed to get the system up and running by splitting the flask app and bokeh server onto two separate app instances, using the allow-origin to ensure the system works. I'd be happy to share a code skeleton if you think it would be useful. Essentially, the bokeh server needs to be started with the $PORT Heroku variable and the pull_session performed on port 80.

The output from autoload_server, i.e. "tag", has http://localhost:5006/, automatically written in by default and I needed to do a str.replace() operation add the correct hostname.

On Thursday, 3 March 2016 19:25:38 UTC+2, Bryan Van de ven wrote:
Hi Matt,

Unfortunately I don't have any experience with Heroku, but in case it is useful there is some information about setting up a Bokeh server behind an (Nginx) proxy here:

        Bokeh server — Bokeh 3.3.2 Documentation

Note that if the Bokeh server and the Flask server doing the autoload_server are on different machines, then you will also need to add --extra-websocket-origin to tell the Bokeh server to accept websocket connections from the Flask server machine (it sounds like you have everything on one VM tho).

Bryan

> On Mar 1, 2016, at 5:35 AM, mattad...@gmail.com wrote:
>
> Hi,
>
> First, I want to say what a wonderful tool Bokeh is. Now, my question. I have set up a small Flask app on a Heroku web dyno that connects to a Bokeh server instance running on a worker dyno. I use Honcho to allow me to run both processes on a single (free) dyno. The Flask app connects to the bokeh server with:
>
> @app.route('/plot')
> def interactive():
> session = pull_session(session_id=None, url='http://localhost:5006/script/&#39;\)
>
> tag = autoload_server(next(iter(session.document.roots)), session_id=session.id,
> app_path='/script')
> session.close()
>
> return render_template('interactive_app.html', tag=tag)
>
> Here "script" is the name of the script launched with "bokeh serve". The whole setup works fine on my local setup (with accept-origin set correctly for local use), however, when run through Heroku the pull_session call looks for a bokeh server instance on my host machine, which makes some sense. I was wondering if anyone has any suggestions on how to correctly proxy the pull_session call to connect to the bokeh server running on the remote worker dyno? I fear my web-application knowledge is rather lacking.
>
> I am currently using bokeh version 0.11.1.
>
>
> --
> 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 bokeh+un...@continuum.io.
> To post to this group, send email to bo...@continuum.io.
> To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/067d1821-5939-4b21-94fb-85e46a8ec46d%40continuum.io\.
> For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

--
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/9ab807e3-75d7-4e63-8add-1cce193ecb8e%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

--
Peter Wang
CTO, Co-founder

--
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/CABGrp%2B_Jf0Bc7ZWm8FUpOeSyyDA1RJkMHxsh0cXnhzJofyWqLQ%40mail.gmail.com\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

There are `url` and `app_path` parameters to autoload_server which in
theory mean you don't need to do this - if those params don't work opening
an issue on github would be welcome.

autoload_server(url='http://myherokuapp.com')

Havoc

···

On Fri, Mar 4, 2016 at 8:45 AM, <[email protected]> wrote:

The output from autoload_server, i.e. "tag", has http://localhost:5006/,
automatically written in by default and I needed to do a str.replace()
operation add the correct hostname.