diff --git a/holoviews/ipython/__init__.py b/holoviews/ipython/__init__.py index 188a06ed04..e2e2df089c 100644 --- a/holoviews/ipython/__init__.py +++ b/holoviews/ipython/__init__.py @@ -186,7 +186,7 @@ def __call__(self, *args, **params): ip = get_ipython() if ip is None else ip # noqa (get_ipython) param_ext.load_ipython_extension(ip, verbose=False) load_magics(ip) - OutputMagic.initialize() + OutputMagic.initialize(list( self._backends.keys())) set_display_hooks(ip) notebook_extension._loaded = True diff --git a/holoviews/ipython/magics.py b/holoviews/ipython/magics.py index 30ee6c7349..894510f76e 100644 --- a/holoviews/ipython/magics.py +++ b/holoviews/ipython/magics.py @@ -256,11 +256,19 @@ class OutputMagic(OptionsMagic): #==========================# last_backend = None + backend_list = [] # List of possible backends def missing_dependency_exception(value, keyword, allowed): raise Exception("Format %r does not appear to be supported." % value) - custom_exceptions = {'holomap':missing_dependency_exception} + def missing_backend_exception(value, keyword, allowed): + if value in OutputMagic.backend_list: + raise ValueError("Backend %r not available. Has it been loaded with the notebook_extension?" % value) + else: + raise ValueError("Backend %r does not exist" % value) + + custom_exceptions = {'holomap':missing_dependency_exception, + 'backend': missing_backend_exception } # Counter for nbagg figures nbagg_counter = 0 @@ -360,7 +368,9 @@ def update_options(cls, options, items): prev_backend = Store.current_backend renderer = Store.renderers[Store.current_backend] prev_backend += ':%s' % renderer.mode - if not backend or backend == prev_backend: + + available = backend in Store.renderers.keys() + if (not backend) or (not available) or backend == prev_backend: return options cls._backend_options[prev_backend] = cls.options @@ -392,7 +402,8 @@ def update_options(cls, options, items): @classmethod - def initialize(cls): + def initialize(cls, backend_list): + cls.backend_list = backend_list backend = cls.options.get('backend', cls.defaults['backend']) if backend in Store.renderers: cls.options = dict(cls.defaults)