posit-dev / py-shinywidgets

Render ipywidgets inside a PyShiny app
MIT License
41 stars 2 forks source link

Question: Popups with ipyleaflet #75

Open RolandASc opened 1 year ago

RolandASc commented 1 year ago

Description

We are trying to develop a Shiny Python app to visualize risks on a leaflet map. A lot of things are working well, but some things we cannot seem to get to work.

What I Did

I went back to the example ipyleaflet app from the README here and tried to include a popup. The popup shows, but I couldn't figure out how I am supposed to set the child element to get any content into the popup. I tried using HTML() from ipywidgets, I tried registering that with register_widget() and a few other things, but the result was always that either the map would not load anymore, or I would get an error like _send_error_response: The 'child' trait of a Popup instance expected a DOMWidget or None

from shiny import *
from shinywidgets import output_widget, register_widget, reactive_read
import ipyleaflet as L
import ipywidgets as W

<...>

    map = L.Map(center=(52, 0), zoom=4)
    pop_child = W.HTML(value="hi")
    register_widget("popchild", pop_child)
    popup = L.Popup(location=(52, 0), child=pop_child)
    map.add(popup)
    register_widget("map", map)

Do you know of any way that I might get this to work?

filipwastberg commented 8 months ago

What version of ipywidgets do you have?