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:
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.
autoload.jshandler 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."*"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.