I know it’s almost 2 years late… but here is a solution using DynamicMap and Pipe:
import holoviews as hv
import panel as pn
from holoviews import opts, streams
hv.extension('bokeh')
def myfunc(data):
print(data)
# changes are here
def polys(data):
return hv.Polygons(data, kdims=['xs', 'ys']).opts(opts.Polygons(fill_alpha=0.3, fill_color='black', active_tools=['poly_draw']))
poly_pipe = streams.Pipe(data={'xs': [], 'ys': []})
poly = hv.DynamicMap(polys, streams=[poly_pipe])
# til here
poly_stream = streams.PolyDraw(source=poly, drag=False, num_objects=0, show_vertices=True,
styles={'fill_color' : 'black'}, vertex_style={'size': 5, 'fill_color': 'white', 'line_color' : 'black'})
poly_stream.add_subscriber(myfunc)
def clearPolys(button):
global poly_stream
print("CLEAR BUTTON PUSHED!!!!!")
poly_stream.event(data={'xs': [], 'ys': []})
poly_pipe.send({'xs': [], 'ys': []})
clearBtn = pn.widgets.Button(name='Clear', button_type='primary')
pn.bind(clearPolys, clearBtn, watch=True)
pn.Row(clearBtn, poly).servable()
I’m reviving this conversation because I’m having a somewhat similar issue with PolyEdit (initially with PolyDraw too, but I found the Pipe workaround above, which unfortunately doesn’t work for the PolyEdit case; see PolyDraw and PolyEdit Tools' Vertices Not Hiding When Switching to Points in Holoviews). I am curious to learn how you re-render stuff on the plot and what is the importance of storing the axes? I tried following your code but it was definitely too complex for me to pinpoint those details. I know it’s been ages but any pointers will be appreciated!