# Buggy code
def _get_sources(self, json, sources):
    datasets = json.get("datasets", {})
    for name in list(datasets):
        if name in sources or isinstance(datasets[name], dict):
            continue
        data = datasets.pop(name)
        columns = set(data[0]) if data else []
        if self.is_altair(self.object):
            import altair as alt

            if not isinstance(self.object.data, alt.Data) and columns == set(
                self.object.data
            ):
                data = ColumnDataSource.from_df(self.object.data)
            else:
                data = ds_as_cds(data)
            sources[name] = ColumnDataSource(data=data)
        else:
            sources[name] = ColumnDataSource(data=ds_as_cds(data))
    data = json.get("data", {}).pop("values", {})
    if data:
        sources["data"] = ColumnDataSource(data=ds_as_cds(data))


# Traceback (KeyError)
KeyError                                  Traceback (most recent call last)
/opt/conda/lib/python3.6/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:

/opt/conda/lib/python3.6/site-packages/panel/viewable.py in _repr_mimebundle_(self, include, exclude)
292         comm = state._comm_manager.get_server_comm()
293         doc = _Document()
--> 294         model = self._render_model(doc, comm)
295         if config.embed:
296             return render_model(model)

/opt/conda/lib/python3.6/site-packages/panel/viewable.py in _render_model(self, doc, comm)
261         if comm is None:
262             comm = state._comm_manager.get_server_comm()
--> 263         model = self.get_root(doc, comm)
264
265         if config.embed:

/opt/conda/lib/python3.6/site-packages/panel/viewable.py in get_root(self, doc, comm)
416         """
417         doc = doc or _curdoc()
--> 418         root = self._get_model(doc, comm=comm)
419         self._preprocess(root)
420         ref = root.ref['id']

/opt/conda/lib/python3.6/site-packages/panel/layout.py in _get_model(self, doc, root, parent, comm)
113         if root is None:
114             root = model
--> 115         objects = self._get_objects(model, [], doc, root, comm)
116         props = dict(self._init_properties(), objects=objects)
117         model.update(**self._process_param_change(props))

/opt/conda/lib/python3.6/site-packages/panel/layout.py in _get_objects(self, model, old_objects, doc, root, comm)
105                 child, _ = pane._models[root.ref['id']]
106             else:
--> 107                 child = pane._get_model(doc, root, model, comm)
108             new_models.append(child)
109         return new_models

/opt/conda/lib/python3.6/site-packages/panel/param.py in _get_model(self, doc, root, parent, comm)
614         if ref in self._models:
615             self._cleanup(root)
--> 616         model = self._inner_layout._get_model(doc, root, parent, comm)
617         self._models[ref] = (model, parent)
618         return model

/opt/conda/lib/python3.6/site-packages/panel/layout.py in _get_model(self, doc, root, parent, comm)
113         if root is None:
114             root = model
--> 115         objects = self._get_objects(model, [], doc, root, comm)
116         props = dict(self._init_properties(), objects=objects)
117         model.update(**self._process_param_change(props))

/opt/conda/lib/python3.6/site-packages/panel/layout.py in _get_objects(self, model, old_objects, doc, root, comm)
105                 child, _ = pane._models[root.ref['id']]
106             else:
--> 107                 child = pane._get_model(doc, root, model, comm)
108             new_models.append(child)
109         return new_models

/opt/conda/lib/python3.6/site-packages/panel/pane/vega.py in _get_model(self, doc, root, parent, comm)
104         else:
105             json = self._to_json(self.object)
--> 106             self._get_sources(json, sources)
107         props = self._process_param_change(self._init_properties())
108         model = VegaPlot(data=json, data_sources=sources, **props)

/opt/conda/lib/python3.6/site-packages/panel/pane/vega.py in _get_sources(self, json, sources)
76                 import altair as alt
77                 if (not isinstance(self.object.data, alt.Data) and
---> 78                     columns == set(self.object.data)):
79                     data = ColumnDataSource.from_df(self.object.data)
80                 else:

/opt/conda/lib/python3.6/site-packages/altair/utils/schemapi.py in __getitem__(self, item)
233
234     def __getitem__(self, item):
--> 235         return self._kwds[item]
236
237     def __setitem__(self, item, val):

KeyError: 0

Row
[0] Column
[0] Select(name='Area type:', options=['Country', 'Sub-Region', ...], value='Country')
[1] ParamFunction(function)

# Fixed code
def _get_sources(self, json, sources):
    datasets = json.get("datasets", {})
    for name in list(datasets):
        if name in sources or isinstance(datasets[name], dict):
            continue
        data = datasets.pop(name)
        columns = set(data[0]) if data else []
        if self.is_altair(self.object):
            import altair as alt

            if not isinstance(
                self.object.data, (alt.Data, alt.UrlData)
            ) and columns == set(self.object.data):
                data = ColumnDataSource.from_df(self.object.data)
            else:
                data = ds_as_cds(data)
            sources[name] = ColumnDataSource(data=data)
        else:
            sources[name] = ColumnDataSource(data=ds_as_cds(data))
    data = json.get("data", {}).pop("values", {})
    if data:
        sources["data"] = ColumnDataSource(data=ds_as_cds(data))