1
import holoviews as hv
from holoviews import dim, opts

import ipywidgets as widgets

# Define a function that creates the widget you want to display

def create_widget(point):                                              
       return widgets.HTML(value=f"You clicked on point ({point[0]},{point[1]})")

# Create a Holoviews plot with the points you want to click on

points = hv.Points([(0, 0), (1, 1), (2, 2)])

Define a callback function that will be triggered when a point is clicked

def click_callback(point):                                       
  widget.value = create_widget(point).repr_html()


# Create a widget that will display information about the clicked point

widget = widgets.HTML()

# Attach the callback function to the plot using the hv.DynamicMap element

dynamic_points = hv.DynamicMap(lambda point: points.select(x=point[0], y=point[1]), streams=[hv.streams.SingleTap(transient=True, callback=click_callback)])dynamic_points.opts(opts.Points(size=10)).redim(x=dim('X Axis'), y=dim('Y Axis'))

# Display the plot and widget

hv.Layout(dynamic_points + widget).cols(2)

I am getting the following error

KeyError: "Callable '<lambda>' missing keywords to accept stream parameters: x,y"

Is there any other way to achieve this? a code snippet will be highly appreciated.

mosc9575
  • 5,618
  • 2
  • 9
  • 32

0 Answers0