PyWebIO icon indicating copy to clipboard operation
PyWebIO copied to clipboard

[Feature Request] Leaflet or Folium integration

Open Filhomn opened this issue 3 years ago • 10 comments

Is there any way to use Leaflet.js on PyWebIO?

Kind Regards

Please move to Discussions - Feature Request for posting.

Filhomn avatar Jun 09 '22 18:06 Filhomn

Do you have to use JS packages? They both have corresponding Python libraries, which can put maps on your pywebio apps.

helincao avatar Jun 09 '22 18:06 helincao

Do you have to use JS packages? They both have corresponding Python libraries, which can put maps on your pywebio apps.

I tried with pywebio.output.put_html(html) for folium, but without success. The Python packages are more limited, so if there is a way to use them in pure js, it would be great!

Filhomn avatar Jun 09 '22 18:06 Filhomn

Please take look at Leafmap: https://github.com/giswqs/leafmap I was able to use put_html to add maps to my page.

helincao avatar Jun 11 '22 17:06 helincao

Do you have to use JS packages? They both have corresponding Python libraries, which can put maps on your pywebio apps.

I tried with pywebio.output.put_html(html) for folium, but without success. The Python packages are more limited, so if there is a way to use them in pure js, it would be great!

@Filhomn

Did you get it to work?

pstatonwx avatar Jun 28 '22 12:06 pstatonwx

It works for me:

from pywebio import *
import folium

def main():
    m = folium.Map(location=[45.5236, -122.6750])
    output.put_html(m)

start_server(main, port=8080, debug=True)

also @pstatonwx

wang0618 avatar Jun 28 '22 12:06 wang0618

@wang0618 thanks! was just checking to see if they were successful :)

pstatonwx avatar Jun 28 '22 12:06 pstatonwx

Yes, I did! Sorry, for not giving the feedback before. I recommend using Ipyleaflet instead of Folium… It is more close to the original Leaflet js library. Thanks!

Filhomn avatar Jun 28 '22 13:06 Filhomn

Yes, it works on jupyter, but it is possible to implement on pywebio as well:

`from ipyleaflet import Map from ipywidgets import embed from pywebio import start_server, config

def bmi(): lat, lon = 18, 95 m = Map(center=(lat,lon), zoom=3) snippet = embed.embed_snippet(views=m) html = embed.html_template.format(title="", snippet=snippet) put_html(html)

if name == 'main': start_server(bmi, port=8080,debug=True, static_dir= './static') `

Filhomn avatar Jun 28 '22 14:06 Filhomn

Awesome!! Haha I deleted my comment right after I posted it because I was like "well that's a dumb thing to ask"

pstatonwx avatar Jun 28 '22 14:06 pstatonwx

Not really dumb… It still doesn’t have the same interactivity as in jupyter. But, It would be great if pywebio works with ipywidgets!

Filhomn avatar Jun 28 '22 14:06 Filhomn