Forums

bokeh-server

Hi all,

I'm a newbie as far as web development is concerned. I am setting up an APP which is built around web2py that uses pandas libraries for number crunching and bokeh for visualization. Since datasets are pretty big, I would like to use also bokeh-server for dynamic visualization. Locally on my own PC the environment is working, but I have some difficulties to let the bojeh-server to run on PA. Any suggestion about how this can be accomplished? Is a paid account needed for running multiple servers / threads? Regards,

Apparently you can "embed the Bokeh server functionality inside another Flask server using the Bokeh Server Flask Blueprint."

That's probably your best bet (ie. set up a separate flask app for it).

First, many thanks for a so prompt reply! Second - as I said, I am a newbie as far as web development is involved. If my main framework is web2py, how can I add a flask app to it? Hence my question about the paid account and multiple app / servers / threads. Any hint (or lecture or link suggestion) well accepted!

There are a couple ways.

  1. you could hack your wsgi file so that it serves multiple web apps at different urls, but I would not suggest this if you are new.
  2. maybe set up another free account and use that as your bokeh server- if it works out of the box, this might be your best choice. However, you will need to do some research into whether the bokeh server needs to talk to your server or get data from your webapp (vs if it only needs info from the client side browser). If it needs more than just the client side info, then you may not be able to set it up this way.
  3. upgrade and set up the second webapp directly within your account- then it can access the mysql db/whatever information needed easily.

Hi, I'd like to know whether the setup of bokeh ultimatly worked, and if so, if you could provide further information. Thanks!

The Bokeh server is implemented as a Flask blueprint, so if you create a Flask web app you can embed the bokeh server into your app.

Great, will give a try, reading up on flask now.

Hi Glenn, after reading a bit and following some tutorials I'm not sure embedding bokeh into flask is really my problem. Although I didn't try it yet, it seems to be straightforward. I think conrad has summed it up nicely, bokeh needs to 'talk' to bokeh-server, so the only solution seems to be to run a second webapp and connect those two. This is where I hoped I'd find some tutorial / further info...

I covered that in this post in the thread that conrad linked to originally.

Hey. I want to build a graph in the Flask application using bokeh. it works well locally, but on PA not work.

There is an error in html:

2018-06-08 09:07:37,297:   File "/home/Fedor/FedorAPIdev/templates/grafic3.html", line 1, in top-level template code
2018-06-08 09:07:37,297:     {% extends 'base.html' %}
2018-06-08 09:07:37,297: 
2018-06-08 09:07:37,297:   File "/home/Fedor/FedorAPIdev/templates/base.html", line 5, in top-level template code
2018-06-08 09:07:37,297:     {% block meta %}
2018-06-08 09:07:37,298: 
2018-06-08 09:07:37,298:   File "/home/Fedor/FedorAPIdev/templates/grafic3.html", line 4, in block "meta"
2018-06-08 09:07:37,298:     {{ js_resources|indent(4)|safe }}
2018-06-08 09:07:37,298: 
2018-06-08 09:07:37,298:   File "/home/Fedor/.virtualenvs/env/lib/python3.6/site-packages/jinja2/filters.py", line 460, in do_indent
2018-06-08 09:07:37,298:     rv = (u'\n' + indention).join(s.splitlines())

html code:

{% extends 'base.html' %}

{% block meta %}
    {{ js_resources|indent(4)|safe }}
    {{ css_resources|indent(4)|safe }}
    {{ plot_script|indent(4)|safe }}

{% endblock %}

{% block content %}
        <div>
            {% if error != None %}
                <h1 style="color: red">Exception: {{ error }}</h1>
            {% endif %}
        </div>

    {{ plot_div|indent(4)|safe }}
{% endblock %}

That's not a useful traceback, it says nothing about the error. Look at the whole traceback.

Maybe it will be useful

2018-06-08 13:23:40 #012Supplying a user-defined data source AND iterable values to glyph methods is#012not possibe. Either:#012#012Pass all data directly as literals:#012#012    p.circe(x=a_list, y=an_array, ...)#012#012Or, put all data in a ColumnDataSource and pass column names:#012#012    source = ColumnDataSource(data=dict(x=a_list, y=an_array))#012    p.circe(x='x', y='y', source=source, ...)
2018-06-08 13:23:40


2018-06-08 13:22:46,973: Error running WSGI application
2018-06-08 13:22:47,009: AttributeError: 'NoneType' object has no attribute 'splitlines'
2018-06-08 13:22:47,009:   File "/home/Fedor/.virtualenvs/env/lib/python3.6/site-packages/flask/app.py", line 1997, in __call__
2018-06-08 13:22:47,009:     return self.wsgi_app(environ, start_response)
2018-06-08 13:22:47,010: 
2018-06-08 13:22:47,010:   File "/home/Fedor/.virtualenvs/env/lib/python3.6/site-packages/flask/app.py", line 1985, in wsgi_app
2018-06-08 13:22:47,010:     response = self.handle_exception(e)
2018-06-08 13:22:47,010: 
2018-06-08 13:22:47,010:   File "/home/Fedor/.virtualenvs/env/lib/python3.6/site-packages/flask/app.py", line 1540, in handle_exception
2018-06-08 13:22:47,010:     reraise(exc_type, exc_value, tb)
2018-06-08 13:22:47,010: 
2018-06-08 13:22:47,010:   File "/home/Fedor/.virtualenvs/env/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
2018-06-08 13:22:47,011:     raise value
2018-06-08 13:22:47,011: 
2018-06-08 13:22:47,011:   File "/home/Fedor/.virtualenvs/env/lib/python3.6/site-packages/flask/app.py", line 1982, in wsgi_app
2018-06-08 13:22:47,011:     response = self.full_dispatch_request()
2018-06-08 13:22:47,011: 
2018-06-08 13:22:47,011:   File "/home/Fedor/.virtualenvs/env/lib/python3.6/site-packages/flask/app.py", line 1614, in full_dispatch_request
2018-06-08 13:22:47,011:     rv = self.handle_user_exception(e)
2018-06-08 13:22:47,011: 
2018-06-08 13:22:47,012:   File "/home/Fedor/.virtualenvs/env/lib/python3.6/site-packages/flask/app.py", line 1517, in handle_user_exception
2018-06-08 13:22:47,012:     reraise(exc_type, exc_value, tb)
2018-06-08 13:22:47,012: 
2018-06-08 13:22:47,012:   File "/home/Fedor/.virtualenvs/env/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
2018-06-08 13:22:47,012:     raise value
2018-06-08 13:22:47,012: 
2018-06-08 13:22:47,012:   File "/home/Fedor/.virtualenvs/env/lib/python3.6/site-packages/flask/app.py", line 1612, in full_dispatch_request
2018-06-08 13:22:47,012:     rv = self.dispatch_request()
2018-06-08 13:22:47,013: 
2018-06-08 13:22:47,013:   File "/home/Fedor/.virtualenvs/env/lib/python3.6/site-packages/flask/app.py", line 1598, in dispatch_request
2018-06-08 13:22:47,013:     return self.view_functions[rule.endpoint](**req.view_args)
2018-06-08 13:22:47,013: 
2018-06-08 13:22:47,013:   File "/home/Fedor/.virtualenvs/env/lib/python3.6/site-packages/flask_httpauth.py", line 93, in decorated
2018-06-08 13:22:47,013:     return f(*args, **kwargs)
2018-06-08 13:22:47,013: 
2018-06-08 13:22:47,013:   File "/home/Fedor/FedorAPIdev/app/views.py", line 1016, in grafic_view
2018-06-08 13:22:47,014:     error=error
2018-06-08 13:22:47,014: 
2018-06-08 13:22:47,014:   File "/home/Fedor/.virtualenvs/env/lib/python3.6/site-packages/flask/templating.py", line 134, in render_template
2018-06-08 13:22:47,014:     context, ctx.app)
2018-06-08 13:22:47,014: 
2018-06-08 13:22:47,014:   File "/home/Fedor/.virtualenvs/env/lib/python3.6/site-packages/flask/templating.py", line 116, in _render
2018-06-08 13:22:47,014:     rv = template.render(context)
2018-06-08 13:22:47,015: 
2018-06-08 13:22:47,015:   File "/home/Fedor/.virtualenvs/env/lib/python3.6/site-packages/jinja2/asyncsupport.py", line 76, in render
2018-06-08 13:22:47,015:     return original_render(self, *args, **kwargs)
2018-06-08 13:22:47,015: 
2018-06-08 13:22:47,015:   File "/home/Fedor/.virtualenvs/env/lib/python3.6/site-packages/jinja2/environment.py", line 1008, in render
2018-06-08 13:22:47,015:     return self.environment.handle_exception(exc_info, True)
2018-06-08 13:22:47,015: 
2018-06-08 13:22:47,015:   File "/home/Fedor/.virtualenvs/env/lib/python3.6/site-packages/jinja2/environment.py", line 780, in handle_exception
2018-06-08 13:22:47,016:     reraise(exc_type, exc_value, tb)
2018-06-08 13:22:47,016: 
2018-06-08 13:22:47,016:   File "/home/Fedor/.virtualenvs/env/lib/python3.6/site-packages/jinja2/_compat.py", line 37, in reraise
2018-06-08 13:22:47,016:     raise value.with_traceback(tb)
2018-06-08 13:22:47,016: 
2018-06-08 13:22:47,016:   File "/home/Fedor/FedorAPIdev/templates/grafic3.html", line 1, in top-level template code
2018-06-08 13:22:47,016:     {% extends 'base.html' %}
2018-06-08 13:22:47,016: 
2018-06-08 13:22:47,016:   File "/home/Fedor/FedorAPIdev/templates/base.html", line 5, in top-level template code
2018-06-08 13:22:47,017:     {% block meta %}
2018-06-08 13:22:47,017: 
2018-06-08 13:22:47,017:   File "/home/Fedor/FedorAPIdev/templates/grafic3.html", line 4, in block "meta"
2018-06-08 13:22:47,017:     {{ js_resources|indent(4)|safe }}
2018-06-08 13:22:47,017: 
2018-06-08 13:22:47,017:   File "/home/Fedor/.virtualenvs/env/lib/python3.6/site-packages/jinja2/filters.py", line 460, in do_indent
2018-06-08 13:22:47,017:     rv = (u'\n' + indention).join(s.splitlines())
2018-06-08 13:23:40,441: Error running WSGI application
2018-06-08 13:23:40,462: AttributeError: 'NoneType' object has no attribute 'splitlines'
2018-06-08 13:23:40,462:   File "/home/Fedor/.virtualenvs/env/lib/python3.6/site-packages/flask/app.py", line 1997, in __call__
2018-06-08 13:23:40,462:     return self.wsgi_app(environ, start_response)
2018-06-08 13:23:40,462: 
2018-06-08 13:23:40,462:   File "/home/Fedor/.virtualenvs/env/lib/python3.6/site-packages/flask/app.py", line 1985, in wsgi_app
2018-06-08 13:23:40,462:     response = self.handle_exception(e)
2018-06-08 13:23:40,462: 
2018-06-08 13:23:40,462:   File "/home/Fedor/.virtualenvs/env/lib/python3.6/site-packages/flask/app.py", line 1540, in handle_exception
2018-06-08 13:23:40,462:     reraise(exc_type, exc_value, tb)
2018-06-08 13:23:40,463: 
2018-06-08 13:23:40,463:   File "/home/Fedor/.virtualenvs/env/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
2018-06-08 13:23:40,463:     raise value
2018-06-08 13:23:40,463: 
2018-06-08 13:23:40,463:   File "/home/Fedor/.virtualenvs/env/lib/python3.6/site-packages/flask/app.py", line 1982, in wsgi_app
2018-06-08 13:23:40,463:     response = self.full_dispatch_request()
2018-06-08 13:23:40,463: 
2018-06-08 13:23:40,463:   File "/home/Fedor/.virtualenvs/env/lib/python3.6/site-packages/flask/app.py", line 1614, in full_dispatch_request
2018-06-08 13:23:40,463:     rv = self.handle_user_exception(e)
2018-06-08 13:23:40,463: 
2018-06-08 13:23:40,463:   File "/home/Fedor/.virtualenvs/env/lib/python3.6/site-packages/flask/app.py", line 1517, in handle_user_exception
2018-06-08 13:23:40,464:     reraise(exc_type, exc_value, tb)
2018-06-08 13:23:40,464: 
2018-06-08 13:23:40,464:   File "/home/Fedor/.virtualenvs/env/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
2018-06-08 13:23:40,464:     raise value
2018-06-08 13:23:40,464: 
2018-06-08 13:23:40,464:   File "/home/Fedor/.virtualenvs/env/lib/python3.6/site-packages/flask/app.py", line 1612, in full_dispatch_request
2018-06-08 13:23:40,464:     rv = self.dispatch_request()
2018-06-08 13:23:40,464: 
2018-06-08 13:23:40,464:   File "/home/Fedor/.virtualenvs/env/lib/python3.6/site-packages/flask/app.py", line 1598, in dispatch_request
2018-06-08 13:23:40,464:     return self.view_functions[rule.endpoint](**req.view_args)
2018-06-08 13:23:40,464: 
2018-06-08 13:23:40,465:   File "/home/Fedor/.virtualenvs/env/lib/python3.6/site-packages/flask_httpauth.py", line 93, in decorated
2018-06-08 13:23:40,465:     return f(*args, **kwargs)
2018-06-08 13:23:40,465: 
2018-06-08 13:23:40,465:   File "/home/Fedor/FedorAPIdev/app/views.py", line 1016, in grafic_view
2018-06-08 13:23:40,465:     error=error
2018-06-08 13:23:40,465: 
2018-06-08 13:23:40,465:   File "/home/Fedor/.virtualenvs/env/lib/python3.6/site-packages/flask/templating.py", line 134, in render_template
2018-06-08 13:23:40,465:     context, ctx.app)
2018-06-08 13:23:40,465: 
2018-06-08 13:23:40,465:   File "/home/Fedor/.virtualenvs/env/lib/python3.6/site-packages/flask/templating.py", line 116, in _render
2018-06-08 13:23:40,466:     rv = template.render(context)
2018-06-08 13:23:40,466: 
2018-06-08 13:23:40,466:   File "/home/Fedor/.virtualenvs/env/lib/python3.6/site-packages/jinja2/asyncsupport.py", line 76, in render
2018-06-08 13:23:40,466:     return original_render(self, *args, **kwargs)
2018-06-08 13:23:40,466: 
2018-06-08 13:23:40,466:   File "/home/Fedor/.virtualenvs/env/lib/python3.6/site-packages/jinja2/environment.py", line 1008, in render
2018-06-08 13:23:40,466:     return self.environment.handle_exception(exc_info, True)
2018-06-08 13:23:40,466: 
2018-06-08 13:23:40,466:   File "/home/Fedor/.virtualenvs/env/lib/python3.6/site-packages/jinja2/environment.py", line 780, in handle_exception
2018-06-08 13:23:40,466:     reraise(exc_type, exc_value, tb)
2018-06-08 13:23:40,466: 
2018-06-08 13:23:40,467:   File "/home/Fedor/.virtualenvs/env/lib/python3.6/site-packages/jinja2/_compat.py", line 37, in reraise
2018-06-08 13:23:40,467:     raise value.with_traceback(tb)
2018-06-08 13:23:40,467: 
2018-06-08 13:23:40,467:   File "/home/Fedor/FedorAPIdev/templates/grafic3.html", line 1, in top-level template code
2018-06-08 13:23:40,467:     {% extends 'base.html' %}
2018-06-08 13:23:40,467: 
2018-06-08 13:23:40,467:   File "/home/Fedor/FedorAPIdev/templates/base.html", line 5, in top-level template code
2018-06-08 13:23:40,467:     {% block meta %}
2018-06-08 13:23:40,467: 
2018-06-08 13:23:40,467:   File "/home/Fedor/FedorAPIdev/templates/grafic3.html", line 4, in block "meta"
2018-06-08 13:23:40,467:     {{ js_resources|indent(4)|safe }}
2018-06-08 13:23:40,467: 
2018-06-08 13:23:40,468:   File "/home/Fedor/.virtualenvs/env/lib/python3.6/site-packages/jinja2/filters.py", line 460, in do_indent
2018-06-08 13:23:40,468:     rv = (u'\n' + indention).join(s.splitlines())

Ok. From that, I'm guessing that js_resources is None in your template, so indent can't indent it. Follow your code back to find out why js_resources is None.