14
14
15
15
class Webapp :
16
16
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 ):
18
18
self ._title = title
19
19
self ._html_template = html_template
20
20
self ._scheme = scheme
21
21
self ._model_factory_fnc = model_factory_fnc
22
22
self ._port = port
23
23
self ._on_session_destroyed = on_session_destroyed
24
+ self ._autostart = autostart
24
25
25
26
def start (self , ioloop = None ):
26
27
'''
@@ -45,13 +46,12 @@ def make_document(doc: Document):
45
46
model = self ._model_factory_fnc (doc )
46
47
doc .add_root (model )
47
48
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 )
49
51
50
52
@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 ):
55
55
'''
56
56
Runs a Bokeh webserver application. Documents will be created using
57
57
fnc_make_document
@@ -64,8 +64,11 @@ def _run_server(fnc_make_document, iplot=True,
64
64
show (app , notebook_url = notebook_url ) # noqa
65
65
else :
66
66
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 } ' )
69
72
server = Server (apps , port = port , io_loop = ioloop )
70
73
if ioloop is None :
71
74
server .run_until_shutdown ()
0 commit comments