I am making an application that involves interacting with large dataset (~750k points) and finding interesting subsets (100-200 points) to analyze. I would like to allow the user to decide whether to enable or disable datashader. I built a little toy demonstrating what I want:
import panel as pn
import holoviews as hv
import datashader
import holoviews.operation.datashader
import numpy as np
hv.extension('bokeh')
should_datashade_start = True
def plot_my_points(color_method, should_datashade):
x = np.arange(-4, 4, 0.01)
y = x**2
if color_method == 'ascending':
z = np.arange(0, len(x))
elif color_method == 'descending':
z = np.flip(np.arange(0, len(x)))
elif color_method == 'random':
z = np.random.rand(*x.shape)
points = hv.Points((x, y, z), kdims=['x', 'y'], vdims=['height'])
if should_datashade:
shaded = hv.operation.datashader.datashade(points, aggregator=datashader.max('height'), cmap='plasma', dynamic=False)
else:
shaded = points.opts(hv.opts.Points(color='height', cmap='plasma'))
return shaded
drop_down = pn.widgets.Select(name='Color By', options=['ascending', 'descending', 'random'], value='ascending')
datashade_switch = pn.widgets.Switch(value=should_datashade_start)
pts = hv.DynamicMap(pn.bind(plot_my_points, color_method=drop_down, should_datashade=datashade_switch, watch=True))
col = pn.Column(pn.pane.HoloViews(pts), drop_down, datashade_switch)
Changing “should_datashade_start” to True or False before running the script works fine, but flipping the switch in the browser causes a crash:
Traceback (most recent call last):
File "/Users/stgardner4/micromamba/envs/interactive-pyxlmadev/lib/python3.11/site-packages/holoviews/plotting/util.py", line 293, in get_plot_frame
return map_obj[key]
~~~~~~~^^^^^
File "/Users/stgardner4/micromamba/envs/interactive-pyxlmadev/lib/python3.11/site-packages/holoviews/core/spaces.py", line 1219, in __getitem__
self._cache(tuple_key, val)
File "/Users/stgardner4/micromamba/envs/interactive-pyxlmadev/lib/python3.11/site-packages/holoviews/core/spaces.py", line 1292, in _cache
self[key] = val
~~~~^^^^^
File "/Users/stgardner4/micromamba/envs/interactive-pyxlmadev/lib/python3.11/site-packages/holoviews/core/ndmapping.py", line 566, in __setitem__
self._add_item(key, value, update=False)
File "/Users/stgardner4/micromamba/envs/interactive-pyxlmadev/lib/python3.11/site-packages/holoviews/core/ndmapping.py", line 165, in _add_item
self._item_check(dim_vals, data)
File "/Users/stgardner4/micromamba/envs/interactive-pyxlmadev/lib/python3.11/site-packages/holoviews/core/ndmapping.py", line 986, in _item_check
raise AssertionError(f"{self.__class__.__name__} must only contain one type of object, not both {type(data).__name__} and {self.type.__name__}.")
AssertionError: DynamicMap must only contain one type of object, not both RGB and Points.
is there a way that I can get around this ‘same types’ issue?