I have tried many methods to dynamically change the fill color in a PolyDraw stream, but none seem to work. For example, in the following code, changing the color in the Selector has no effect on the fill color of the polygons:
Here is the code:
#%%
import holoviews as hv
from holoviews import opts, streams
import panel as pn
import param
hv.extension('bokeh')
#%%
class ClassPoly(param.Parameterized):
colors = [ 'red', 'blue', 'green', 'yellow' ]
class_selector = param.Selector(colors, default='red' )
poly = hv.Polygons([]).opts( fill_alpha = 1.0 )
poly_stream = streams.PolyDraw( source=poly, show_vertices=True,
styles= dict( fill_alpha=1.0, fill_color = [ "black" ] ) )
@param.depends('class_selector', watch=True)
def update_selection(self):
class_color = self.class_selector
self.poly_stream.styles.update( fill_color = [ class_color ] )
#%%
cp = ClassPoly()
pn.Row( cp.param.class_selector, cp.poly )
#%%