1

I've been around this bug for a while and any help will be appreciated.

Im trying to deploy a panel/bokeh application on Openshift/K8s, The application seems to work correctly, however the browser doesn't display the bokeh/app widget.

Here is the app code:

Flask serves on 0.0.0.0/8080 and reroutes to the bokeh server on 0.0.0.0/5006.

from threading import Thread
import panel as pn
from flask import Flask, render_template
from tornado.ioloop import IOLoop
from bokeh.embed import server_document
from bokeh.layouts import column
from bokeh.models import ColumnDataSource, Slider
from bokeh.plotting import figure
from bokeh.sampledata.sea_surface_temperature import sea_surface_temperature
from bokeh.server.server import Server
from bokeh.themes import Theme
from bokeh.io import show
from bokeh.models import Button, CustomJS
app = Flask(__name__)


def bkapp(doc):
    doc.add_root(Button(label="Foo", button_type="success"))
    doc.theme = Theme(filename="theme.yaml")


@app.route('/', methods=['GET', 'OPTIONS', 'HEAD'])
def bkapp_page():
    script = server_document('http://0.0.0.0: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': bkapp}, io_loop=IOLoop(), allow_websocket_origin=["*"])
    server.start()
    server.io_loop.start()

Thread(target=bk_worker).start()

if __name__ == '__main__':
    print('Opening single process Flask app with embedded Bokeh application on http://0.0.0.0:8080/')
    print()
    print('Multiple connections may block the Bokeh app in this configuration!')
    print('See "flask_gunicorn_embed.py" for one way to run multi-process')
    app.run(host='0.0.0.0', port=8080)

atemplates/embed.html file that allow us to "embeed" the bokeh/panel html

<!doctype html>

<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Embedding a Bokeh Server With {{ framework }}</title>
</head>

<body>
  <div>
    This Bokeh app below served by a Bokeh server that has been embedded
    in another web app framework. For more information see the section
    <a  target="_blank" href="https://docs.bokeh.org/en/latest/docs/user_guide/server.html#embedding-bokeh-server-as-a-library">Embedding Bokeh Server as a Library</a>
    in the User's Guide.
  </div>
  {{ script|safe }}
</body>
</html>

When I deploy it, i get this message from the browser console

Access to XMLHttpRequest at 'http://0.0.0.0:5006/bkapp/autoload.js?bokeh-autoload-element=de42b2ca-6eb9-40fc-97d8-6b5b52f88d33&bokeh-app-path=/bkapp&bokeh-absolute-url=http://0.0.0.0:5006/bkapp' from origin '<HTTPS ORIGIN>' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Browser:

enter image description here

Thanks

I've tried different Bokeh/app combinations. In my machine it works! meaning local deployment is possible. the problem seems to be the deployment on openshift or the CORS policy of the bokeh server

The question is how can i modify the tornado server directly via the bokeh.server.server used onmy python code I understand it should be the service on 0.0.0./5006 that should forward the necesarry headers, however it seems to evade me rn.

8
  • Are you using a very old version of Bokeh? Bokeh's autoload.js handler definitely sets the CORS header, and has for at least four years now. If not then then something upstream must be interfering but I don't know anything at all about Openshift to be able to comment about that. Commented Sep 13, 2024 at 15:31
  • yes I checked, I'm using Bokeh 3.4.3 and I see the default headers as : def set_default_headers(self): self.set_header("Access-Control-Allow-Headers", "") self.set_header('Access-Control-Allow-Methods', 'PUT, GET, OPTIONS') self.set_header("Access-Control-Allow-Origin", "") Commented Sep 13, 2024 at 16:33
  • I'm not sure what you are looking at. Version 3.4.3 clearly sets the value to "*" not to "" github.com/bokeh/bokeh/blob/3.4.3/src/bokeh/server/views/… In any case this seems like it must be an upstream issue, but I can't help with that. Commented Sep 14, 2024 at 15:03
  • I continued to try to insert the headers on the response request. It is unclear to me how to add the cors headers to the bokeh server. I also tried to add the headers on the bokeh.embeed.server_document function. Nevertheless, I am shifting to another solution to dpeloy my webApp. Sadly, I don't think panel is exactly poduction ready. I think any person who wants to deploy this tool on a prodution envionment with restrictions/certificates etc shall find the same problem somewhere along the way. Cheers Commented Sep 18, 2024 at 6:45
  • 1
    Thanks for your comments and taking the time to answer. Allow me to correct: I couldn't get panel ready to production on my corporate system. Whenever I deploy on localhost I see the headers but when I deploy on OpenShift I loose them. Therefore I think your assertion is TRUE. I will continue to dig on the matter and if I find the answer I will report it. Believe me, I have 6 months worth of code on panel I didn't want to loose Commented Sep 18, 2024 at 18:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.