quarto-dev / quarto-cli

Open-source scientific and technical publishing system built on Pandoc.
https://quarto.org
Other
3.93k stars 325 forks source link

Geopandas output not rendered correctly #2866

Open betolink opened 2 years ago

betolink commented 2 years ago

Bug description

A while ago I rendered qmd files with the following Python code:

import geopandas

world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))
world = world[(world.pop_est>0) & (world.name!="Antarctica")]

world['gdp_per_cap'] = round((world.gdp_md_est * 1e6) / world.pop_est, 2)

world.explore(
     column="gdp_per_cap", # make choropleth based on "BoroName" column
     popup=True, # show all values in popup (on click)
     # tiles="CartoDB positron", # use "CartoDB positron" tiles
     cmap="viridis", # use "Set1" matplotlib colormap
     style_kwds=dict(color="black") # use black outline
    )

and worked just fine giving me the following:

geopandas-map

Now it renders like this

current_output

Looking at the generated md file I noticed that it used to be an iframe with encoded html using the data-html tag. Now it generates an iframe with srcdoc and the output is not url-encoded

geopandas-output

I'm using the latest stable release 1.1.251 and when it worked I was using 0.9.345

Checklist

betolink commented 2 years ago

Update: the HTML output encoding comes from geopandas, the weird thing is that the output renders fine in a Jupyter notebook but not when we use quarto render

betolink commented 2 years ago

The issue can be traced back to this commit on Branca https://github.com/python-visualization/branca/commit/eefe45c5fdaa6a39d02d88464e8dfb6c233d9cfb Folium's template engine, which in turn is used to render maps in Geopandas. This commit changed the iframe property from data-html to srcdoc in the rendered HTML, looks like this causes the inner HTML to be not encoded and not cross domain. I don't know if Quarto could be smart enough to fix this kind of outputs from Jupyter widgets on the fly but Geopandas is widely used in the GIS world so it would be nice if there can be a solution on this side.