Using IIS and flask: the contents of the bokeh server doesn't show

I am trying to launch my bokeh application on Microsoft IIS server via flask. Server administration and Windows are not my strong suits so it might be that I am missing something trivial.

The result is that one can access the page launched by flask but it doesn’t include my bokeh application. When I go to the localhost that contains my bokeh server it seem to work but I can not access that from outside the server computer itself.

I started with the example for embedding bokeh in flask: (I could not link properly due to being a new user but it is the one at examples/howto/server_embed/flask_embed.py)
and then followed the guide for launching flask on IIS: https://medium.com/@bilalbayasut/deploying-python-web-app-flask-in-windows-server-iis-using-fastcgi-6c1873ae0ad8

Any help would be really appreciated! :slight_smile:

My code:

FlaskWrapper.py
from flask import Flask, render_template

from bokeh.embed import server_document
from tornado.ioloop import IOLoop
from threading import Thread
from bokeh.server.server import Server

import MainInterface


def modify_doc(doc):
    MainInterface.modify_doc(doc)


app = Flask(__name__)


@app.route('/refengine/', methods=['GET'])
def bkapp_page():
    script = server_document('http://localhost:5006/bkapp')
    return render_template("embed.html", script=script, template="Flask")


def bk_worker():
    # Can't pass num_procs > 1 in this configuration. If you need to run multiple
    # processes, see e.g. flask_gunicorn_embed.py
    server = Server({'/bkapp': modify_doc}, io_loop=IOLoop())
    server.start()
    server.io_loop.start()


Thread(target=bk_worker).start()

if __name__ == '__main__':
    app.run()
embed.html
<!doctype html>

<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Application</title>
</head>

<body>
  <div>
    This is text from embed.html
  </div>
  {{ script|safe }}
</body>
</html>
MainInterface.py
from bokeh.layouts import column
from bokeh.models.widgets import PreText


class MainInterface:

    def __init__(self):
        # There is more here but removed for simplicity
        pass


def modify_doc(doc):
    me.status_text = PreText(text="WELCOME", width=1600)
    doc.add_root(column(me.status_text))


me = MainInterface()

Are there any errors or messages in the Browser’s JavaScript console log? What about the Bokeh server logs?

Thank you so much investing time in my issue! :slight_smile:
I have already left work (living in Sweden GMT+2) so will have to check tomorrow for the JavaScript console log.
Where do I find where the Bokeh server logs are printed?

There are printed from whatever process you have embedded the Bokeh server in. But I think you will need to call bokeh.util.logging.basicConfig() to enable it.

Ok, so the JS log tells me that the connection is refused. Not sure why though:

GET http://localhost:59612/bkapp/autoload.js?bokeh-autoload-element=1008&bokeh-app-path=/bkapp&bokeh-absolute-url=http://localhost:59612/bkapp net::ERR_CONNECTION_REFUSED

Due to my inexperience with IIS it took some time to get to the bokeh logs but when I finally got it to work this is what I found:

DEBUG:bokeh.server.tornado:[pid 7048] 0 clients connected
DEBUG:bokeh.server.tornado:[pid 7048]   /bkapp has 0 sessions with 0 unused

It is solved now. There were several problems (including settings on the server) but the most embarrassing one is that I didn’t realize I needed to change localhost. :sweat:
Thanks for the help anyway :slight_smile:

1 Like

@Drakryttare If you have time to write up a short summary of all the issues I am sure it would be helpful to future users (and perhaps points to something to add in the documentation)

Sorry for not noticing your reply. I might have missed something but here is what helped me:

Faults that blocked me: