Repository: holoviz/panel

Issue:
jscallback does not work in templates
This example :
```python
import panel as pn
pn.extension()

markdown = pn.pane.Markdown('Markdown display')
text_input = pn.widgets.TextInput(value=markdown.object)

text_input.jscallback(args={'markdown':markdown}, value='markdown.text = source.value')

template = """
{% extends base %}

{% block contents %}
{{ app_title }}
<div style="display:table; width: 100%">
  <div style="display:table-cell; margin: auto">
    {{ embed(roots.text_input) }}
  </div>
  <div style="display:table-cell; margin: auto">
    {{ embed(roots.markdown) }}
  </div>
</div>
{% endblock %}
"""

tmpl = pn.Template(template,)

tmpl.add_panel('text_input', pn.panel(text_input))
tmpl.add_panel('markdown', pn.panel(markdown))

tmpl.servable()
```
produce:
```
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
~/PythonWorkspace/py37/lib/python3.7/site-packages/IPython/core/formatters.py in __call__(self, obj, include, exclude)
    968 
    969             if method is not None:
--> 970                 return method(include=include, exclude=exclude)
    971             return None
    972         else:

~/PythonWorkspace/modules/panel/panel/template.py in _repr_mimebundle_(self, include, exclude)
    156         doc = _Document()
    157         comm = state._comm_manager.get_server_comm()
--> 158         self._init_doc(doc, comm, notebook=True)
    159         return render_template(doc, comm)
    160 

~/PythonWorkspace/modules/panel/panel/template.py in _init_doc(self, doc, comm, title, notebook)
    113         ref = preprocess_root.ref['id']
    114         for name, (obj, tags) in self._render_items.items():
--> 115             model = obj.get_root(doc, comm)
    116             doc.on_session_destroyed(obj._server_destroy)
    117             for sub in obj.select(Viewable):

~/PythonWorkspace/modules/panel/panel/viewable.py in get_root(self, doc, comm)
    527         doc = doc or _curdoc()
    528         root = self._get_model(doc, comm=comm)
--> 529         self._preprocess(root)
    530         ref = root.ref['id']
    531         state._views[ref] = (self, root, doc, comm)

~/PythonWorkspace/modules/panel/panel/viewable.py in _preprocess(self, root)
    348         """
    349         for hook in self._preprocessing_hooks:
--> 350             hook(self, root)
    351 
    352     def _render_model(self, doc=None, comm=None):

~/PythonWorkspace/modules/panel/panel/links.py in _process_callbacks(cls, root_view, root_model)
    126             overrides = arg_overrides.get(id(link), {})
    127             callbacks.append(cb(root_model, link, src, tgt,
--> 128                                 arg_overrides=overrides))
    129         return callbacks
    130 

~/PythonWorkspace/modules/panel/panel/links.py in __init__(self, root_model, link, source, target, arg_overrides)
    205         specs = self._get_specs(link, source, target)
    206         for src_spec, tgt_spec, code in specs:
--> 207             self._init_callback(root_model, link, source, src_spec, target, tgt_spec, code)
    208 
    209     @classmethod

~/PythonWorkspace/modules/panel/panel/links.py in _init_callback(self, root_model, link, source, src_spec, target, tgt_spec, code)
    270 
    271         for k, v in dict(link.args, **self.arg_overrides).items():
--> 272             arg_model = self._resolve_model(root_model, v, None)
    273             if arg_model is not None:
    274                 references[k] = arg_model

~/PythonWorkspace/modules/panel/panel/links.py in _resolve_model(cls, root_model, obj, model_spec)
    243                 model = obj.handles[handle_spec]
    244         elif isinstance(obj, Viewable):
--> 245             model, _ = obj._models[root_model.ref['id']]
    246         elif isinstance(obj, BkModel):
    247             model = obj

KeyError: '1046'
```


Discussion:
Don't know if it's related but:
This code sample is not working properly
```python
# Not working
volume = pn.panel(np.random.rand(10,10,10))
mkd = pn.pane.Markdown()
volume.jscallback(args={'mkd': mkd}, colormap="""
console.log(source.colormap)
mkd.text = source.colormap
""")
pn.Column(volume, mkd)
```
In the js console the callback seems triggered and the value for the colormap is ok
but the markdown panel does not update

Whereas this sample of code works as expected
```python
# working
volume = pn.panel(np.random.rand(10,10,10))
mkd = pn.pane.Markdown()
volume.jslink(target=mkd, colormap="text")
pn.Column(volume, mkd)
```

Resolving patch:
diff --git a/panel/links.py b/panel/links.py
--- a/panel/links.py
+++ b/panel/links.py
@@ -204,8 +204,11 @@ def __init__(self, root_model, link, source, target=None, arg_overrides={}):
         self.validate()
         specs = self._get_specs(link, source, target)
         for src_spec, tgt_spec, code in specs:
-            self._init_callback(root_model, link, source, src_spec, target, tgt_spec, code)
-
+            try:
+                self._init_callback(root_model, link, source, src_spec, target, tgt_spec, code)
+            except Exception:
+                pass
+                
     @classmethod
     def _resolve_model(cls, root_model, obj, model_spec):
         """


Test patch: