我想使用m.add_layer
for Popus
from ipyleaflet in shiny for python(as given here)。但是,它没有按预期工作。我的最小工作示例如下所示:
from shiny import App, render, ui
from shinywidgets import output_widget, reactive_read, register_widget
from ipywidgets import HTML
from ipyleaflet import Map, Marker, Popup
app_ui = ui.page_fluid(
output_widget("m")
)
def server(input, output, session):
center = (52.204793, 360.121558)
m = Map(center=center, zoom=9, close_popup_on_click=False)
message1 = HTML()
message1.value = "Try clicking the marker!"
# Popup with a given location on the map:
popup = Popup(
location=center,
child=message1,
close_button=False,
auto_close=False,
close_on_escape_key=False
)
m.add_layer(popup) # This line is not working
register_widget("m", m)
app = App(app_ui, server)
想知道我错过了什么?
1条答案
按热度按时间ikfrs5lh1#
看起来
m.add_layer(popup)
行不起作用,因为您试图将ipyleafletMap
对象用作Shiny小部件,但Shiny无法识别它,因此您可以使用shinywidgets
中的output_widget
函数从ipyleafletMap
对象创建一个Shiny小部件,然后使用add_layer
方法将弹出窗口添加到Map中;