Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.
[Jupyter] add _repr_html_ method (#1202)
François BAPTISTE1b7484710726
diff --git a/bindings/kepler.gl-jupyter/keplergl/keplergl.py b/bindings/kepler.gl-jupyter/keplergl/keplergl.pyindex fe1efa768..632e10d7f 100644--- a/bindings/kepler.gl-jupyter/keplergl/keplergl.py+++ b/bindings/kepler.gl-jupyter/keplergl/keplergl.py@@ -135,24 +135,23 @@ class KeplerGl(widgets.DOMWidget):self.data = copy- def save_to_html(self, data=None, config=None, file_name='keplergl_map.html', read_only=False, center_map=False):- ''' Save current map to an interactive html+ def _repr_html_(self, data=None, config=None, read_only=False, center_map=False):+ ''' Return current map in an html encoded stringInputs:- 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- - file_name: the html file name, default is keplergl_map.html- read_only: if read_only is True, hide side panel to disable map customizationReturns:- - an html file will be saved to your notebook+ - a html encoded stringExample of use:# this will save map with provided data and config- keplergl.save_to_html(data={"data_1": df}, config=config, file_name='first_map.html')+ keplergl._repr_html_(data={"data_1": df}, config=config)# this will save current map- keplergl.save_to_html(file_name='first_map.html')+ keplergl._repr_html_()'''keplergl_html = resource_string(__name__, 'static/keplergl.html').decode('utf-8')@@ -170,7 +169,31 @@ class KeplerGl(widgets.DOMWidget):cmd = """window.__keplerglDataConfig = {};""".format(keplergl_data)frame_txt = keplergl_html[:k] + "<body><script>" + cmd + "</script>" + keplergl_html[k+6:]- with open(file_name,'wb') as f:- f.write(frame_txt.encode('utf-8'))+ return frame_txt.encode('utf-8')++ def save_to_html(self, data=None, config=None, file_name='keplergl_map.html', read_only=False, center_map=False):+ ''' Save current map to an interactive html++ Inputs:+ - 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+ - file_name: the html file name, default is keplergl_map.html+ - read_only: if read_only is True, hide side panel to disable map customization++ Returns:+ - an html file will be saved to your notebook++ Example of use:+ # this will save map with provided data and config+ keplergl.save_to_html(data={"data_1": df}, config=config, file_name='first_map.html')++ # this will save current map+ keplergl.save_to_html(file_name='first_map.html')++ '''+ frame_txt = self._repr_html_(data=data, config=config, read_only=read_only, center_map=center_map)++ with open(file_name, 'wb') as f:+ f.write(frame_txt)print("Map saved to {}!".format(file_name))