This is the kepler.gl jupyter widget, an advanced geospatial visualization tool, to render large-scale interactive maps in Jupyter Notebook.
Table of contacts
conda install -c conda-forge keplergl
- Python >= 3.7
pip install keplergl
- For kelplergl <= 0.3.0
- Python >= 2
- ipywidgets >= 7.0.0
If you're on Mac, used pip install
, and you're running Notebook 5.3 and above, you don't need to run the following:
jupyter nbextension install --py --sys-prefix keplergl # can be skipped for notebook 5.3 and above
jupyter nbextension enable --py --sys-prefix keplergl # can be skipped for notebook 5.3 and above
NOTE: For No Module named 'keplergl' error, please make sure your virtual environment is activated and has been added to the Jupyter kernel.
Use the following command to check the kernel list:
jupyter kernelspec list
Use the following command to add the virtual environment to the Jupyter kernel:
python -m ipykernel install --user --name=myenv
The --name
parameter is your preferred name to identify the virtual environment
keplergl
(>0.3.0) works with Google Colab. You can install it using pip.
# Install keplergl (>0.3.0)
!pip install keplergl
NOTE: keplergl
<=0.3.0 doesn't work with JupyterLab 3. You need to make sure the python package keplergl
> 0.3.0 is installed.
Installation using pip:
pip install keplergl
Installation using conda:
conda install keplergl
There is no need to use jupyter labextension install
for keplergl
> 0.3.0 with JupyterLab3.
For JupyterLab1, you need to install keplergl-jupyter
labextension from NPM registery. There is no need to install keplergl
python package.
First, install jupyterlab-manager
for JupyterLab1:
jupyter labextension install @jupyter-widgets/[email protected]
Then, install keplergl-jupyter
labextension from NPM registry:
jupyter labextension install keplergl-jupyter
- Node >= 12
- Python 3
For JupyterLab2, you need to install keplergl-jupyter
labextension from NPM registery. There is no need to install keplergl
python package.
First, install jupyterlab-manager
for JupyterLab2:
jupyter labextension install @jupyter-widgets/jupyterlab-manager@2
To install keplergl-jupyter
from NPM registry, JupyterLab2 has following requirements of dependencies:
JupyterLab Extension Package
>=16.9.0 <16.10.0 >=17.0.0 <18.0.0 react
>=16.9.0 <16.10.0 >=17.0.0 <18.0.0 react-dom
However, keplergl-jupyter
<=0.3.0 depends on react
>= 17.0.2. Therefore, the latest keplergl-jupyter
can’t be installed with JupyterLab2: if you use jupyter labextension install keplergl-jupyter
, the version 0.2.2 as a fallback will be installed. Unfortunately, version 0.2.2 does NOT work with JupyterLab2.
A workaround is to modify the file lib/python3.x/site-packages/jupyterlab/staging/package.json
and remove “react” and “react-dom” from “singletonPackages” object. Then, install keplergl-jupyter using this command:
jupyter labextension install keplergl-jupyter
- Node >= 12
- Python 3
NOTE: please make sure the python kernel is correctly specified in the notebook.
# Load kepler.gl with an empty map
from keplergl import KeplerGl
map_1 = KeplerGl(height=400)
map_1
# Load kepler.gl with map data and config
# Since keplergl 0.3.4, you can pass `use_arrow=True` to load and render data faster using GeoArrow, e.g. `KeplerGl(data={'data_1': df}, config=config, use_arrow=True)`
map_2 = KeplerGl(height=400, data={'data_1': df}, config=config)
map_2
# Add data to map
# Since keplergl 0.3.4, you can pass `use_arrow=True` to load and render data faster using GeoArrow, e.g. `map_1.add_data(df, 'data_1', use_arrow=True)`
map_1.add_data(df, 'data_1')
# Apply config
map_1.config(config)
# print data and config
map_1.data
map_1.config
# save map to html
map_1.save_to_html(file_name='keplergl_map.html')
Keplergl (>0.3.0) works with Google Colab. You can install it using pip.
# Install keplergl (>0.3.0)
!pip install keplergl
# Load Kepler.gl with an empty map
from keplergl import KeplerGl
map_1 = KeplerGl()
# Display map
map_1.show()
The function show()
is newly introduced for displaying map in Google Colab. The function is defined as:
def show(self, data=None, config=None, read_only=False, center_map=False)
with input parameters:
- data: a data dictionary {"name": data}, if not provided, will use current map data
- config: map config dictionary, if not provided, will use current map config
- read_only: if read_only is True, hide side panel to disable map customization
- center_map: if center_map is True, the bound of the map will be updated acoording to the current map data
Please note that the map is not interactive due to the limitation of Google Colab. For example, when applying config to the map in Colab, the map won't be updated and one needs to call show()
again to render a new map in a new cell.
- Load kepler.gl: Load kepler.gl widget, add data and config
- Geometry as String: Embed Polygon geometries as
GeoJson
andWKT
inside aCSV
- GeoJSON: Load GeoJSON to kepler.gl
- DataFrame: Load DataFrame to kepler.gl
- GeoDataFrame: Load GeoDataFrame to kepler.gl
https://docs.kepler.gl/docs/keplergl-jupyter#1-load-keplergl-map
- 1. Load kepler.gl
- 2. Add Data
- 3. Data Format
- 4. Customize the map
- 5. Save and load config
- 6. Match config with data
- 7. Save Map
You will need to install node, yarn and Jupyter Notebook.
Install node > 12
, and yarn. Use nvm for better node version management e.g. nvm install 12
.
- Using conda
conda install jupyter
conda install notebook 6.0.1
- Using pip
pip install jupyter
pip install notebook==6.0.1
- Using conda
conda install geopandas
- Using pip
pip install geopandas
git clone https://github.com/keplergl/kepler.gl.git
cd bindings/kepler.gl-jupyter
cd js
yarn
Add Mapbox access token to Node env.
export MapboxAccessTokenJupyter=<your_mapbox_token>
npm start
You need to run step 2 and 3 to restart the js program. And step 1-3 if any js dependency has changed (Usually after pulling new changes from master).
This command must be run AFTER the js
setup, and folder static/
was created. It only needs to be run once.
# dev install from folder containing setup.py
pip install -e .
# only needed in dev mode, not in normal mode.
jupyter nbextension install --py --symlink --sys-prefix keplergl
# only needed in dev mode, not in normal mode.
jupyter nbextension enable --py --sys-prefix keplergl
NOTE: The above command jupyter nbextension install -py --symlink --sys-prefix keplergl
is trying to create a symoblic link of the folder bindings/kepler.gl-jupyter/keplergl/static
under the jupyter's folder nbextensions
. Please check if there is already a folder "nbextensions/kepler-jupyter" existed, and you might need to remove it first.
To find the location of nbextensions
folder, you can use the following command:
$ where jupyter
/Users/test/opt/anaconda3/envs/test37/bin/jupyter
# the nbextensions should be at: /Users/test/opt/anaconda3/envs/test37/share/jupyter/nbextensions
cd notebooks
jupyter notebook
You can now start editing the .js and .py files to see changes reflected in your local notebook. After changing files in the js folder, the local start script will recompile the js files and put them in to keplergl/static
folder. You need to reload the jupyter notebook page to reload the files.
To test the development work in previous 2 steps for JupyterLab. You can build the keplergl labextension
under the js
directory:
jupyter labextension build .
The output of the jupyter labextension is defined in the file js/package.json
:
...
"jupyterlab": {
"extension": "babel/labplugin",
"outputDir": "../keplergl-jupyter/labextension",
"sharedPackages": {
"@jupyter-widgets/base": {
"bundled": false,
"singleton": true
}
}
}
Then, you can either install this labextension to test it:
jupyter labextension install .
or, you can manually create a symbolic link for the folder bindings/kepler.gl-jupyter/kepler-jupyter/labextension
under the jupyter's folder labextensions
, e.g. /Users/test/opt/anaconda3/envs/test37/share/jupyter/labextensions
. You will need to reload the jupyter lab page.