error of map to html #237
-
Hi, when I was trying to export my map as html, I got an error: "Exception: 'NoneType' object has no attribute 'comm_id' ". How to fix this problem? Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 1 reply
-
It works fine on my end. import leafmap
m = leafmap.Map()
m.add_basemap('HYBRID')
m.to_html("mymap.html")
m |
Beta Was this translation helpful? Give feedback.
-
I encounter the exact same question. ---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
File C:\ProgramData\Anaconda\envs\py39\lib\site-packages\leafmap\leafmap.py:1747, in Map.to_html(self, outfile, title, width, height, add_layer_control, **kwargs)
1745 self.layout.height = height
-> 1747 self.save(outfile, title=title, **kwargs)
1749 self.layout.width = before_width
File C:\ProgramData\Anaconda\envs\py39\lib\site-packages\ipyleaflet\leaflet.py:2518, in Map.save(self, outfile, **kwargs)
2509 """Save the Map to an .html file.
2510
2511 Parameters
(...)
2516 Extra parameters to pass to the ipywidgets.embed.embed_minimal_html function.
2517 """
-> 2518 embed_minimal_html(outfile, views=[self], **kwargs)
File C:\ProgramData\Anaconda\envs\py39\lib\site-packages\ipywidgets\embed.py:302, in embed_minimal_html(fp, views, title, template, **kwargs)
288 """Write a minimal HTML file with widget views embedded.
289
290 Parameters
(...)
300 {embed_kwargs}
301 """
--> 302 snippet = embed_snippet(views, **kwargs)
304 values = {
305 'title': title,
306 'snippet': snippet,
307 }
File C:\ProgramData\Anaconda\envs\py39\lib\site-packages\ipywidgets\embed.py:264, in embed_snippet(views, drop_defaults, state, indent, embed_url, requirejs, cors)
252 """Return a snippet that can be embedded in an HTML file.
253
254 Parameters
(...)
261 A unicode string with an HTML snippet containing several `<script>` tags.
262 """
--> 264 data = embed_data(views, drop_defaults=drop_defaults, state=state)
266 widget_views = u'\n'.join(
267 widget_view_template.format(view_spec=escape_script(json.dumps(view_spec)))
268 for view_spec in data['view_specs']
269 )
File C:\ProgramData\Anaconda\envs\py39\lib\site-packages\ipywidgets\embed.py:219, in embed_data(views, drop_defaults, state)
217 if state is None:
218 # Get state of all known widgets
--> 219 state = Widget.get_manager_state(drop_defaults=drop_defaults, widgets=None)['state']
221 # Rely on ipywidget to get the default values
File C:\ProgramData\Anaconda\envs\py39\lib\site-packages\ipywidgets\widgets\widget.py:418, in Widget.get_manager_state(drop_defaults, widgets)
417 for widget in widgets:
--> 418 state[widget.model_id] = widget._get_embed_state(drop_defaults=drop_defaults)
419 return {'version_major': 2, 'version_minor': 0, 'state': state}
File C:\ProgramData\Anaconda\envs\py39\lib\site-packages\ipywidgets\widgets\widget.py:427, in Widget._get_embed_state(self, drop_defaults)
422 state = {
423 'model_name': self._model_name,
424 'model_module': self._model_module,
425 'model_module_version': self._model_module_version
426 }
--> 427 model_state, buffer_paths, buffers = _remove_buffers(self.get_state(drop_defaults=drop_defaults))
428 state['state'] = model_state
File C:\ProgramData\Anaconda\envs\py39\lib\site-packages\ipywidgets\widgets\widget.py:591, in Widget.get_state(self, key, drop_defaults)
590 to_json = self.trait_metadata(k, 'to_json', self._trait_to_json)
--> 591 value = to_json(getattr(self, k), self)
592 if not PY3 and isinstance(traits[k], Bytes) and isinstance(value, bytes):
File C:\ProgramData\Anaconda\envs\py39\lib\site-packages\ipywidgets\widgets\widget.py:57, in _widget_to_json(x, obj)
56 elif isinstance(x, Widget):
---> 57 return "IPY_MODEL_" + x.model_id
58 else:
File C:\ProgramData\Anaconda\envs\py39\lib\site-packages\ipywidgets\widgets\widget.py:528, in Widget.model_id(self)
525 """Gets the model id of this widget.
526
527 If a Comm doesn't exist yet, a Comm will be created automagically."""
--> 528 return self.comm.comm_id
AttributeError: 'NoneType' object has no attribute 'comm_id'
During handling of the above exception, another exception occurred:
Exception Traceback (most recent call last)
Cell In[32], line 3
1 m = leafmap.Map()
2 m.add_basemap("HYBRID")
----> 3 m.to_html("mymap.html")
4 m
File C:\ProgramData\Anaconda\envs\py39\lib\site-packages\leafmap\leafmap.py:1761, in Map.to_html(self, outfile, title, width, height, add_layer_control, **kwargs)
1758 return out_html
1760 except Exception as e:
-> 1761 raise Exception(e)
Exception: 'NoneType' object has no attribute 'comm_id' I've searched online and found no solutions at all. Please help. Thanks a lot. |
Beta Was this translation helpful? Give feedback.
-
I came across the same error and made hundreds of tests to find the reason, to no avail. The workaround I found is as follows. Instead of using this (using Ipyleaflet): Use folium like this (using folium): That way I can export to HMTL with no problems. Lastly, thanks for this great software!!! |
Beta Was this translation helpful? Give feedback.
-
Try the following code. If it does not work, it is an ipyleaflet problem. import ipyleaflet
m = ipyleaflet.Map()
m.save('map.html') |
Beta Was this translation helpful? Give feedback.
-
Thanks so much for your answer. Yes, effectively I get the error. In case it is of any use, I copy the error log below.
|
Beta Was this translation helpful? Give feedback.
-
Well, now that we narrowed it down a bit more, it seems that the problem might be 'environment-dependent'. I am using JupyterLab 4.0.5 but I tried anyway (installed the extension) and the error is gone. Thanks again for geemap, for your help and for being so responsive. |
Beta Was this translation helpful? Give feedback.
-
Jupyterlab 4.x also has some issues with ipyleaflet. See jupyterlab/jupyterlab#14829 |
Beta Was this translation helpful? Give feedback.
It works fine on my end.