opengeos / leafmap

A Python package for interactive mapping and geospatial analysis with minimal coding in a Jupyter environment
https://leafmap.org
MIT License
3.22k stars 386 forks source link

Unable to get leafmap maps in the documentation rendering from a jupyter notebook in mkdocs? #516

Closed bgriffen closed 1 year ago

bgriffen commented 1 year ago

Description

I am trying to create my own mkdocs page and all is running well. I then wanted to render the leafmap maps from the Jupyter notebooks exactly as it is here. I thought by lifting the relevant parts of the mkdocs yaml config for leafmap thinking I would be able to render Jupyter notebooks but not having any success. The text/code blocks update but no map renders.

Source code

mkdocs.yml:

plugins:
    - search
    - mkdocstrings
    - mkdocs-jupyter:
          include_source: True
          ignore_h1_titles: True
          execute: True
          include_requirejs: true
          allow_errors: false
          ignore: ["conf.py"]
          execute_ignore:
              [
                  "*.ipynb",
              ]

Just starting with even a basic notebook import/display as follows:

leafmap

My result on my mkdocs page as such:

result

Was there additional things in the mkdocs.yml that I'm missing or something else to get the map to display? I tried the other feature request in 2021 related to this but didn't lead anywhere. Any help appreciated. Thank you.

giswqs commented 1 year ago

Unfortunately, I don't think mkdocs-jupyter supports rendering ipywidgets. See https://github.com/danielfrg/mkdocs-jupyter/issues/67. The mkdocs-jupyter maintainer never responded to the request, so I closed it.

For the leafmap mkdocs, I use folium to render it. See https://github.com/opengeos/leafmap/blob/master/leafmap/__init__.py#L22

prncevince commented 1 year ago

Was scratching my head on this a bit as well but this issue/question clarified things. Thank you.

Also, a helpful resource here is understanding how to select from the different backends of Leafmap.

For the solution above make sure that the environment variable is set before importing leafmap:

import os
os.environ['USE_MKDOCS'] = 'True'
import leafmap
m = leafmap.Map()
m

Or you can select & set the folium backend directly:

import leafmap.foliumap
m2 = leafmap.foliumap.Map()
m2

We get the same results for both. And renders nicely as quarto html output as well.

image