starcore-explorer-bad/content/pyodide/folium.ipynb

155 lines
4.3 KiB
Plaintext
Raw Permalink Normal View History

2023-06-24 01:19:43 +08:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"tags": []
},
"source": [
"# `folium` Interactive Map Demo\n",
"\n",
"Simple demonstration of rendering a map in a `jupyterlite` notebook.\n",
"\n",
"Note that the `folium` package has several dependencies which themselves may have dependencies.\n",
"\n",
"The following code fragement, run in a fresh Python enviroment into which `folium` has already been installed, identifies the packages that are loaded in when `folium` is loaded:\n",
"\n",
"```python\n",
"#https://stackoverflow.com/a/40381601/454773\n",
"import sys\n",
"before = [str(m) for m in sys.modules]\n",
"import folium\n",
"after = [str(m) for m in sys.modules]\n",
"set([m.split('.')[0] for m in after if not m in before and not m.startswith('_')])\n",
"```\n",
"\n",
"The loaded packages are:\n",
"\n",
"```\n",
"{'branca',\n",
" 'certifi',\n",
" 'chardet',\n",
" 'cmath',\n",
" 'csv',\n",
" 'dateutil',\n",
" 'encodings',\n",
" 'folium',\n",
" 'gzip',\n",
" 'http',\n",
" 'idna',\n",
" 'importlib',\n",
" 'jinja2',\n",
" 'markupsafe',\n",
" 'mmap',\n",
" 'numpy',\n",
" 'pandas',\n",
" 'pkg_resources',\n",
" 'pytz',\n",
" 'requests',\n",
" 'secrets',\n",
" 'stringprep',\n",
" 'urllib3',\n",
" 'zipfile'}\n",
" ```\n",
" "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The following packages seem to need installing in order load `folium`, along with folium itself:\n",
"\n",
"```\n",
"chardet, certifi, idna, branca, urllib3, Jinja2, requests, Markupsafe\n",
"```\n",
"\n",
"Universal wheels, with filenames of the form `PACKAGE-VERSION-py2.py3-none-any.whl` appearing in the *Download files* area of a PyPi package page ([example](https://pypi.org/project/requests/#files)] are required in order to install the package.\n",
"\n",
"One required package, [`Markupsafe`](https://pypi.org/project/Markupsafe/#files)) *did not* have a universal wheel available, so a wheel was manually built elsewhere (by hacking the [`setup.py` file](https://github.com/pallets/markupsafe/blob/main/setup.py) to force it to build the wheel in a platform and speedup free way) and pushed to a downloadable location in an [*ad hoc* wheelhouse](https://opencomputinglab.github.io/vce-wheelhouse/)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"trusted": true
},
"outputs": [],
"source": [
"# Install folium requirements\n",
"%pip install -q folium"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Demo of `folium` Map\n",
"\n",
"Load in the `folium` package:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"trusted": true
},
"outputs": [],
"source": [
"import folium"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"And render a demo map:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"trusted": true
},
"outputs": [],
"source": [
"m = folium.Map(location=[50.693848, -1.304734], zoom_start=11)\n",
"m"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python (Pyodide)",
"language": "python",
"name": "python"
},
"language_info": {
"codemirror_mode": {
"name": "python",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8"
},
"orig_nbformat": 4,
"toc-showcode": false
},
"nbformat": 4,
"nbformat_minor": 4
}