Repository: bokeh/bokeh

Issue:
Load bokehjs in a notebook during `import bokeh`
Testing for notebook is cheap, so we could just `load_notebook()` in `bokeh.__init__` and fail silently if not available. That would allow us to skip writing this: 

```
from bokeh import load_notebook
load_notebook()
```

in every notebook.



Discussion:
:+1:

Agreed. (If we are in the notebook and it fails, don't be silent of course)

One disadvantage is that we lose any control over how `load_notebook()` is called, so we can't use verbose mode, nor configure resources. However, there could be a function to alter the configuration or one could fall back to environmental variables.


Resolving patch:
diff --git a/bokeh/__init__.py b/bokeh/__init__.py
--- a/bokeh/__init__.py
+++ b/bokeh/__init__.py
@@ -1,7 +1,11 @@
 from __future__ import absolute_import, print_function
+
 import warnings
-from ._version import get_versions
 from . import utils
+from . import sampledata
+from ._version import get_versions
+from .settings import settings
+
 try:
     from .__conda_version__ import conda_version
     __version__ = conda_version.replace("'","")
@@ -10,10 +14,9 @@
     __version__ = get_versions()['version']
     del get_versions
 
-
 _notebook_loaded = None
 
-def load_notebook(resources=None, verbose=False, force=False, skip=False):
+def load_notebook(resources=None, verbose=False, hide_banner=False):
     ''' Prepare the IPython notebook for displaying Bokeh plots.
 
     Args:
@@ -23,8 +26,8 @@ def load_notebook(resources=None, verbose=False, force=False, skip=False):
         verbose (bool, optional) :
             whether to report detailed settings (default: False)
 
-        force (bool, optional) :
-            whether to skip IPython notebook check (default: False)
+        hide_banner (bool, optional):
+            whether to hide the Bokeh banner (default: False)
 
     Returns:
         None
@@ -32,18 +35,6 @@ def load_notebook(resources=None, verbose=False, force=False, skip=False):
     '''
     global _notebook_loaded
 
-    # It's possible the IPython folks will chance things in the future, `force` parameter
-    # provides an escape hatch as long as `displaypub` works
-    if not force:
-        notebook = False
-        try:
-            notebook = 'notebook' in get_ipython().config.IPKernelApp.parent_appname
-        except Exception:
-            pass
-        if not notebook:
-            raise RuntimeError('load_notebook only works inside an '
-                               'IPython notebook, try using force=True.')
-
     from .resources import INLINE
     from .templates import NOTEBOOK_LOAD, RESOURCES
 
@@ -79,12 +70,24 @@ def load_notebook(resources=None, verbose=False, force=False, skip=False):
         css_info = css_info,
         bokeh_version = __version__,
         warnings = warnings,
-        skip = skip,
+        hide_banner = hide_banner,
     )
     utils.publish_display_data({'text/html': html})
 
-from .settings import settings
-from . import sampledata
+# load the notebook by default but let the door open for customization, also
+# fail silently if IPython is not there.
+resources = settings.notebook_resources()
+verbose = settings.notebook_verbose()
+hide_banner = settings.notebook_hide_banner()
+
+# whether to skip the load_notebook at __init__
+skip_load = settings.notebook_skip_load()
+
+try:
+    if not skip_load:
+        load_notebook(resources=resources, verbose=verbose, hide_banner=hide_banner)
+except ImportError:
+    pass
 
 def _print_versions():
     import platform as pt
diff --git a/bokeh/plotting.py b/bokeh/plotting.py
--- a/bokeh/plotting.py
+++ b/bokeh/plotting.py
@@ -369,15 +369,11 @@ def output_server(docname, session=None, url="default", name=None, clear=True):
     if clear:
         curdoc().clear()
 
-def output_notebook(url=None, docname=None, session=None, name=None,
-                    force=False):
+def output_notebook(url=None, docname=None, session=None, name=None):
     if session or url or name:
         if docname is None:
             docname = "IPython Session at %s" % time.ctime()
         output_server(docname, url=url, session=session, name=name)
-    else:
-        from . import load_notebook
-        load_notebook(force=force)
     global _default_notebook
     _default_notebook = True
 
diff --git a/bokeh/settings.py b/bokeh/settings.py
--- a/bokeh/settings.py
+++ b/bokeh/settings.py
@@ -52,6 +52,18 @@ def pythonlib(self, default=None):
     def simple_ids(self, default=None):
         return self._get_bool("SIMPLE_IDS", default)
 
+    def notebook_resources(self, default=None):
+        return self._get_str("NOTEBOOK_RESOURCES", default)
+
+    def notebook_verbose(self, default=None):
+        return self._get_bool("NOTEBOOK_VERBOSE", default)
+
+    def notebook_hide_banner(self, default=None):
+        return self._get_bool("NOTEBOOK_HIDE_BANNER", default)
+
+    def notebook_skip_load(self, default=None):
+        return self._get_bool("NOTEBOOK_SKIP_LOAD", default)
+
     """
     Server settings go here:
     """


Test patch: