bokehdebug-mode

How to start Bokeh server programmatically in dev / debug mode


I'm still developing my project and I want to make a lot of changes to UI through HTML/CSS, I'm starting the Bokeh server programmatically and it looks like this:

from tornado.ioloop import IOLoop
from tornado.web import StaticFileHandler
from bokeh.server.server import Server
from bokeh.application import Application
from bokeh.application.handlers.function import FunctionHandler
from os.path import dirname, join
import sys
if not dirname(__file__) in sys.path: sys.path.append(dirname(__file__))
from models.ProjectDataLoading import modify_page1
from models.Empty import modify_page2

page1_app = Application(FunctionHandler(modify_page1))
page2_app = Application(FunctionHandler(modify_page2))
StaticFileHandler.reset()
io_loop = IOLoop.current()

server = Server(applications = {'/ProjectDataLoading': page1_app,
                                '/PrimaveraObjects': page2_app,
                                '/SpecializedReports': page2_app,
                                '/StatisticalReports': page2_app,
                                '/Predictions': page2_app},
                                extra_patterns=[(r'/static/css/(.*)', StaticFileHandler, {'path':join(dirname(__file__),"static","css")})],
                                io_loop = io_loop, port = 5006, static_hash_cache=False, debug=True, autoreload=True, compiled_template_cache=False, serve_traceback=True)

server.start()
server.show('/ProjectDataLoading')
io_loop.start() 

I'm still working on page1 -> "ProjectDataLoading", and as you can see I'm trying to make the server to stop cashing the static files with the following codes:

StaticFileHandler.reset()
static_hash_cache=False
debug=True

of course, it's wrong, because it's related to tornado application, not Bokeh server, so, how can I do it Bokeh server?


Solution

  • Almost all the code to support dev mode, i.e. watching a list file files and auto-reloading, is in the application part of the Bokeh server, not in the library. So you would need to essentially reproduce the code here:

    https://github.com/bokeh/bokeh/blob/8f9cf0a85ba51098da2d027150e900bfc073eeba/bokeh/command/subcommands/serve.py#L785-L816