Navigating between Flask and bokeh

Hi all,

I have a question regarding the navigation between a Flask application and a bokeh server app.
In my case, I would like to include buttons (e.g., “Back” or “Cancel”), which should me take back to the Flask application again (means: some of its routes).

My solution up to now is:
to add a JS function tied to a button click that takes you to a certain URL. But if I change Flask routes or directories on the server, this connection will break. So it would be great if I could refer to a route with the help of flask.redirect or something similar.

Thanks!

If you are running the Bokeh server as a separate process, there’s not going to be any way the Bokeh app can know your Flask app’s routes, or be able to call Flask APIs from Bokeh callbacks. You’d have to keep the links up to date manually, or build some automation. However, you might consider embedding the Bokeh app inside a Flask page, instead of navigating away to it. Then you could have standard Flask navigation things in the top level page that embeds Bokeh, that do use Flask features like flask.redirect.

Alternatively, if you are embedding the Bokeh server as a library inside a Flask app, then I guess there is some chance that Flask APIs might work. I can’t say for sure, you’d just have to try.

Hi Bryan,

thank you for your help! I’m already embedding the app into a Flask page, but needed some possibility to do something when closing the app (saving changes, etc.). But as you recommend, it may be best to do the non-graphical things outside bokeh with the help of Flask.

By the way, I like bokeh and hope that it will have a long life!

MT

Not too sure how this would pan out but I need to write to a my flask db from a panel app (https://panel.holoviz.org/).

I ended up importing create_app into my panel/bokeh app this gives access to the flask config where you could stick say the host url?

Also through bokeh.Document.session_context.request.arguments you have access to arguments passed to the bokeh document and maybe bokeh.Document.session_context.request._request could be used somehow?