1414
1515class Webapp :
1616 def __init__ (self , title , html_template , scheme , model_factory_fnc ,
17- on_session_destroyed = None , port = 80 ):
17+ on_session_destroyed = None , port = 80 , autostart = False ):
1818 self ._title = title
1919 self ._html_template = html_template
2020 self ._scheme = scheme
2121 self ._model_factory_fnc = model_factory_fnc
2222 self ._port = port
2323 self ._on_session_destroyed = on_session_destroyed
24+ self ._autostart = autostart
2425
2526 def start (self , ioloop = None ):
2627 '''
@@ -45,13 +46,12 @@ def make_document(doc: Document):
4546 model = self ._model_factory_fnc (doc )
4647 doc .add_root (model )
4748
48- self ._run_server (make_document , ioloop = ioloop , port = self ._port )
49+ self ._run_server (make_document , ioloop = ioloop , port = self ._port ,
50+ autostart = self ._autostart )
4951
5052 @staticmethod
51- def _run_server (fnc_make_document , iplot = True ,
52- notebook_url = 'localhost:8889' ,
53- port = 80 , ioloop = None ):
54-
53+ def _run_server (fnc_make_document , notebook_url = 'localhost:8889' ,
54+ iplot = True , ioloop = None , port = 80 , autostart = False ):
5555 '''
5656 Runs a Bokeh webserver application. Documents will be created using
5757 fnc_make_document
@@ -64,8 +64,11 @@ def _run_server(fnc_make_document, iplot=True,
6464 show (app , notebook_url = notebook_url ) # noqa
6565 else :
6666 apps = {'/' : app }
67- print (f'Browser is launching at: http://localhost:{ port } ' )
68- view (f'http://localhost:{ port } ' )
67+ if autostart :
68+ print (f'Browser is launching at: http://localhost:{ port } ' )
69+ view (f'http://localhost:{ port } ' )
70+ else :
71+ print (f'Open browser at: http://localhost:{ port } ' )
6972 server = Server (apps , port = port , io_loop = ioloop )
7073 if ioloop is None :
7174 server .run_until_shutdown ()
0 commit comments