☰Read-only archive⌕
Looking for help with Bokeh?

This is a read-only archive. Ask questions and join the conversation on GitHub.

Visit Community Support on GitHub →
Archived discussions · Captured October 28, 2026

Deploy Bokeh Server into production on IP address

Community Support
_jm
_jm

My understanding is that your main.py is similar to the bokeh flask embed examples, wherein doc is an argument to the bk_app() function.

The session context is a property of a bokeh document, so look at doc.session_context If you can append/add data to it from the application lifecycle hooks in app_hooks.py, you should be able to access the info you need in that bk_app() function.

⌁   Link to post
alexgrossman
alexgrossman

So can this be run in a Flask app and not Bokeh serve? I really don’t entirely understand how this is supposed to be done. The examples on github aren’t very clear. I have to get this done tonight because of all of the deployment issues, sorry for constantly bugging you.

⌁   Link to post
_jm
_jm

Not a requirement for using a Flask app. I was just trying to tie it to what you originally posted.

It is really a function of how you’ve organized your code. If you hold on to the bokeh document for a session in a variable that is accessible to other parts of your code, you can access it as a property of the bokeh document. It has nothing to do with Flask per se. That is just how that original main.py file exposed the bokeh document.

⌁   Link to post
alexgrossman
alexgrossman

I meant other way around. Seems from the documentation like running “bokeh serve” is a requirement for using lifecycle hooks. When I try to use them in a flask app, they don’t register. I’m unsure how I could use bokeh serve and still have other users on my network be able to use it.

⌁   Link to post
alexgrossman
alexgrossman

Do you know if there’s any sort of bokeh support phone number I can call? Having a lot of trouble here and have been struggling for many hours with a very simple deployment issue that’s forcing me to change around my entire application @Bryan @_jm

⌁   Link to post
Bryan
Bryan

You can use lifecycle hooks in a Flask context, but it is an advanced and uncommon thing to do, and does not have all the conveniences that the “directory format” bokeh server apps with an app_hooks.py file has. You will have to create an actual handler class to configure on the application:

from bokeh.application import Application
from bokeh.application.handlers import FunctionHandler
from bokeh.application.handlers.lifecycle import LifecycleHandler
class MyHandler(LifecycleHandler):
    def on_server_loaded(self, server_context):
        print("SERVER LOADED")
bkapp = Application(FunctionHandler(bkapp), MyHandler())

As for sharing data created in the server loaded hook, there’s a near infinite range of possibilities, from a shared database each session connects to, to pre-processed files that every session loads. Alternatively you can use Python a module that all sessions import. Have the hook store some module global and then all sessions that import the module will automatically see that immediately simply due to how Python itself caches modules. The spectrogram example does this with an audio.py module:

https://github.com/bokeh/bokeh/tree/branch-2.2/examples/app/spectrogram

This is really terrible that I can’t have multiple users use this app on Windows?

You can certainly have multiple users, in general. I just opened the bokeh serve --show sliders.py example on Windows and then opened 10 simultaneous windows. That’s just with one process, since the actual work the app does in callbacks is minimal. But if there is a long server startup time, or long individual session startup time, expensive blocking work in callbacks, all of these things will point towards more sophisticated approaches. Bokeh is not magic. If there is 10 minutes of startup time Bokeh can’t make that disappear. Whether and how things might become more involved and sophisticated to deal with situations like that depends on the actual specifics of what kind of work the app does, about which we know almost nothing.

Do you know if there’s any sort of bokeh support phone number I can call?
I would really appreciate some support here.

I just have to reiterate that Bokeh is an open source project run on a volunteer basis, not a business of any sort.

⌁   Link to post
alexgrossman
alexgrossman

I’ve read through that example. I’m just creating a dictionary of dataframes that I need to call when running “bkapp,” That dictionary is reading from text files so if I have to read and write again, I’m not sure how well LifecycleHandlers will work relative to what I’m already doing.

To go back to the original issue, is there definitely no way to use multiple threads in Windows? I know that you can open 10 simple apps at the same time but if there’s a nonneglible load time then using one thread is really bulky.

I’m not meaning to criticize so I’m sorry if it came off that way, I just spent a month developing a bokeh app (during my first month of work ever, I just graduated from university) and thought it would be a relatively simple transition to allow it to work through multiple threads but I’m now being told that that doesn’t seem possible so naturally I’m a little distraught that I may have to go to my boss to tell him this needs to be redone in Javascript to function correctly (after I just presented the app to him and his bosses).

If you have any suggestions for how to use multiple threads in windows and avoid the Thread-1 error I was getting before, it would be incredibly appreciated. @Bryan

⌁   Link to post
Bryan
Bryan

I don’t, offhand. I’m not a regular Windows user by any stretch. None of the core devs are regular Windows users. That’s one of the challenges of volunteer OSS: you only get whoever chooses to show up. We make sure basic usage for standalone and notebook and bokeh serve running works on Windows. I would love for someone to decide they want to be the “Windows Maintainer” for Bokeh to help develop and document more advanced scenarios like this, but as of yet no one has taken up the role.

This is something I could potentially spend time investigating myself, given a Minimal, Reproducible Example to start with. But to set expectations: we are in the middle of a release and I also have a day job, so the turnaround time on that would be measured in days. And again: the first, absolutely necessary step is to provide a compete example and instructions to reproduce what you are seeing, without any modifications or guessing about missing details.

⌁   Link to post
alexgrossman
alexgrossman

The example that was sent by @_jm is a minimal reproducible example. It doesn’t work on my Windows 10 system with Bokeh 2.0.2 but it works on @_jm’s.

I get the error:

RuntimeError: There is no current event loop in thread ‘Thread-1’.
As of now, I cannot find a fix for this.

Could you help me come up with a workaround for now? I would create multiple Flask apps under different ports, but I can’t even get that to work on windows as the document doesn’t load unless the port for server_document is :5006, do you have any suggestions for why that may be the case? I can send a relevant minimal reproducible example right now if that works best. Sorry for taking up your time on this.

⌁   Link to post
alexgrossman
alexgrossman

If I can actually complete this bokeh project, I would need to maintain it in Windows and would be happy to try to help with Windows Maintenance for bokeh. (I’m not sure how qualified I would be though, I studied CS at MIT but nothing in this area, but would love to try to learn!)

⌁   Link to post
Bryan
Bryan

I don’t, because this thread has gotten quite long and there are too many threads. What would solve that: A gist, with everything ready to copy and paste into local files, with instructions for me to run.

⌁   Link to post

End of archived discussion · Replies are disabled