Ipyleaflet not found in WASM/Pyodide-worker

So I have a nice dashboard with ipyleaflet, where I can drag a marker around to pick a location, and then update a number of panel widgets, run some functions, etc. On my local machines, it works great (for the sake of argument, I’ll be using the same code as in here):

from ipyleaflet import Map, Marker

import panel as pn

pn.extension("ipywidgets", sizing_mode="stretch_width")

from ipyleaflet import Map, Marker

ACCENT_BASE_COLOR = "#DAA520"


def get_marker_and_map():
    center = (52.204793, 360.121558)

    lmap = Map(center=center, zoom=15, height=500)

    marker = Marker(location=center, draggable=True)
    lmap.add_layer(marker)
    lmap.layout.height="100%"
    lmap.layout.width="100%"
    return marker, lmap

marker, lmap = get_marker_and_map()

json_widget = pn.pane.JSON({}, height=75)

def on_location_changed(event):
    new = event["new"]
    json_widget.object = {"x": new[0], "y": new[1]}
marker.observe(on_location_changed, 'location')

component = pn.Column(
    pn.panel(lmap, sizing_mode="stretch_both", min_height=500),
    json_widget
)

template = pn.template.FastListTemplate(
    site="Awesome Panel",
    title="IPyLeaflet",
    logo="https://panel.holoviz.org/_static/logo_stacked.png",
    header_background=ACCENT_BASE_COLOR,
    accent_base_color=ACCENT_BASE_COLOR,
    main=[component],
).servable()

However, when I convert this into a Pyodide page with requirements.txt given as

ipywidgets
ipyleaflet
pyviz_comms
panel

and then using

panel convert something.py --to pyodide-worker \
     --out out --requirements ./requirements.txt 

and serving the resulting page (and .js file) in the browser shows that it install bokeh, panel etc, gets as far as “Executing code”, and then it comes up with ModuleNotFound error: No module named ipyleaflet. Which is weird, because it reported installing ipyleaflet a few second before!

If I convert to pyodide rather than pyodide-worker, the web page just hangs and there are no messages on installing packages etc.

Any hints very appreciated!

Hi @xgomez

I tried following your instructions and I see a lot of errors in the browser console.

I don’t think that Panel+Ipywidgets+Pyodide works yet. At least Panel+Ipywidgets+Jupyterlite does not work (See Ipywidgets not working in Panelite).

I created a bug report in #4500

1 Like