Hi,
I’m trying to connect panel apps to flask. There are some ideas about this already here: https://docs.bokeh.org/en/latest/docs/user_guide/server.html
from flask import Flask, render_template
from bokeh.client import pull_session
from bokeh.embed import server_session
app = Flask(__name__)
@app.route('/', methods=['GET'])
def bkapp_page():
with pull_session(url="http://localhost:5006/sliders") as session:
# update or customize that session
session.document.roots[0].children[1].title.text = "Special Sliders For A Specific User!"
# generate a script to load the customized session
script = server_session(session_id=session.id, url='http://localhost:5006/sliders')
# use the script in the rendered page
return render_template("embed.html", script=script, template="Flask")
if __name__ == '__main__':
app.run(port=8080)
Effectively, if I understand correctly, I need to use the pull_session
. In order to do that correctly, I need to figure out what port panel was running on. I could of course assign a port by hand and use that one, but having the program randomly select an open one is handy (and might even be required if my idea expands to multiple users)
My current thinking is to use pn.serve
and then figure out the port number from the object that returns. However, if I run pn.serve
with something I want to display, the program blocks:
a = pn.serve(gs) # gs is a GridSpec with some plots/buttons/whatever
print(a) # doesn't print until I hit Ctrl-C
print(dir(a))
Is there a way to do this? Is this even the correct approach, or am I on the wrong path here?