marker.on_click misbehave in python shiny

53 Views Asked by At

I'm using shiny and python for a project and I run into an interesting behavior.

My code should create a marker and equip this marker with a function once the marker is clicked.

from ipyleaflet import Marker, Map, MarkerCluster

map = Map(center=(0, 0), zoom=5, scroll_wheel_zoom=True)

def a(x):
    print(x)

x=0
markers = []

for i in range(5):
    marker = Marker(location = (0,0), draggable=False)
    marker.on_click(a(x))
    x+=1
    markers.append(mark)

marker_cluster = MarkerCluster(markers=markers)
map.add_layer(marker_cluster)

There is probably some issue within the for loop as when the map is plotted (I'm building a shiny app), it prints to terminal 0 and 1, but when I click on the marker nothing happens.

0

There are 0 best solutions below