randyzwitch / streamlit-folium

Streamlit Component for rendering Folium maps
https://folium.streamlit.app/
MIT License
468 stars 176 forks source link

bidrectional streamlit support breaks rendering of vector tiles #183

Closed cboettig closed 5 months ago

cboettig commented 5 months ago

I'm using the leafmap package to create a bidirectional streamlit-folium application, which for the most part is very nice and easy. However, I have noticed that while folium continues to render COGs or geojson just fine, vector tiles fail to render. I reported this in leafmap, but we're having trouble tracking down the issue precisely, it looks like the problem originates in streamlit-folium.

Here's a relatively minimal example. When bidirectional = True, we get the bidirectional output from the draw tools, but the vector tiles layers (tribal areas polygons) no longer render. With bidirectional turned off the vector tile layer renders quickly, but of course the app no longer has bidirectional interactions.


import leafmap.foliumap as leafmap
bidirectional = False
pmtiles = "https://data.source.coop/cboettig/us-boundaries/tribal-lands.pmtiles"
style = {
    "version": 8,
    "sources": {
        "source1": {
            "type": "vector",
            "url": "pmtiles://" + pmtiles}},
    "layers": [{
            "id": "layer1",
            "source": "source1",
            "source-layer": "US_Domestic_Sovereign_Nations%3A_Land_Areas_of_Federally-Recognized_Tribes_(BIA)",
            "type": "fill"}]}

m  = leafmap.Map()
m.add_cog_layer("https://data.source.coop/cboettig/carbon/cogs/irrecoverable_c_total_2018.tif", palette="Reds", name="carbon", transparent_bg=True, opacity = 0.9)
# m.add_geojson("https://raw.githubusercontent.com/opengeos/leafmap/master/examples/data/countries.geojson")
m.add_pmtiles(pmtiles)
st_data = m.to_streamlit(height = 400, bidirectional = bidirectional)

if bidirectional:
    st_data
randyzwitch commented 5 months ago

I'm not quite following @cboettig...this code originates in leafmap, which isn't our package. Not sure how we could be "breaking" something they are doing?

randyzwitch commented 5 months ago

Ah, I see what they are doing.

Are you on the latest version of streamlit-folium? We made a change recently that is supposed to better import all needed JS, maybe that fixes this? I'm running your example locally, it looks like it works to me.

Screenshot 2024-04-30 at 2 43 50 PM
cboettig commented 5 months ago

Amazing! Yup, updated my libraries and things are working great. Thanks for this amazing package!

(here's a little demo streamlit app illustrating your bidirectional support to explore carbon stocks and carbon lost https://huggingface.co/spaces/boettiger-lab/leafmap)

randyzwitch commented 5 months ago

Woo hoo!