gmaps icon indicating copy to clipboard operation
gmaps copied to clipboard

Colab not displaying maps

Open RandomForestRanger opened this issue 7 years ago • 16 comments
trafficstars

Very inexperienced - so this might be a rookie error. Using Colab running python 3. When I run

import gmaps
import ipywidgets as widgets
-
gmaps.configure(api_key="AIxrza...")
-
#code where I get the dataframe fooDF which contains, among others, cols 'latitude' and 'longitude'>
-
locations = fooDF[['latitude', 'longitude']]
weights = fooDF['time_precision']
fig = gmaps.figure()
fig = gmaps.figure(map_type='TERRAIN')
fig.add_layer(gmaps.heatmap_layer(locations, weights=weights))
fig

my only output is

Figure(layout=FigureLayout(height='420px'))

And if I tweak above code by inserting, right at the top,

!jupyter nbextension enable --py --sys-prefix widgetsnbextension

it simply tells me that

ImportError: No module named widgetsnbextension

At a loss, any help, please?

RandomForestRanger avatar Nov 21 '18 09:11 RandomForestRanger

Thanks for raising this.

I don't know much about Colab. How did you install gmaps? By running !pip install gmaps in a notebook?

pbugnion avatar Nov 22 '18 07:11 pbugnion

Thanks for picking this up. Yes, I ran

!pip install gmaps
!pip install ipywidgets
!pip install widgetsnbextension

..and it looks as if Colab doesn't support widgets, and perhaps that's were things fall down. If there's a workaround, or any advice, I'd be most thankful.

RandomForestRanger avatar Nov 22 '18 09:11 RandomForestRanger

gmaps leans on widgets very heavily. It definitely won't work if you can't get widgets working. I'd also say widgets are a core part of Jupyter, so if you're right that Colab doesn't support them, that's a bit disappointing.

I'm not sure I have much advice beyond either:

  • pushing Colab to make widgets work (depending on the amount of leverage you have with Colab)
  • using Jupyter directly locally
  • using another Jupyter as a service provider that isn't Colab. I'd expect many of them support widgets.

pbugnion avatar Nov 22 '18 13:11 pbugnion

Understood and agreed on all points. Thanks Pascal.

RandomForestRanger avatar Nov 22 '18 15:11 RandomForestRanger

I'd actually keep this issue open until we have gmaps working on Colab (even if it isn't a gmaps specific issue).

pbugnion avatar Nov 22 '18 19:11 pbugnion

Got stuck since gmaps example didn't work in Colab. Figured that was a google implementation problem. Got Jupyter Lab working in Anaconda. Same thing... get output of: Figure(layout=FigureLayout(height='420px'))

DakotaHoosier avatar Nov 26 '18 01:11 DakotaHoosier

Went over to Jupyter's Binder site and had the same issue (output doesn't render in notebook). Is there a way to save output to a HTML file?

DakotaHoosier avatar Nov 26 '18 01:11 DakotaHoosier

gmaps definitely works with JupyterLab. Make sure you follow the entire set of instructions.

And yes, you can save the output as html.

pbugnion avatar Nov 26 '18 08:11 pbugnion

The same problem still exists as of Aug 26, 2019. Colab vs gmaps should really work together - aren't they all from the Google shop? ;)

frank-yifei-wang avatar Aug 26 '19 22:08 frank-yifei-wang

Colab vs gmaps should really work together - aren't they all from the Google shop

I am not in any way affiliated with Google.

pbugnion avatar Oct 08 '19 13:10 pbugnion

gmaps does kind of "work" on Colab if you are alright making an export.html file per @pbugnion's post above: https://github.com/pbugnion/gmaps/issues/281#issuecomment-441550836

After making the file, you just need to run:

import IPython
IPython.display.HTML(filename='export.html')

aiban avatar Nov 09 '19 05:11 aiban

gmaps does kind of "work" on Colab if you are alright making an export.html file per @pbugnion's post above: #281 (comment)

After making the file, you just need to run:

import IPython
IPython.display.HTML(filename='export.html')

This works! However the output is not displayed when publishing the notebook to Github. Anyone know a workaround?

nicolabc avatar Jan 14 '20 15:01 nicolabc

Hi guys, I have the same problem as the person who created the link. Can someone explain me how can I see the map by using export.html?

Thanks guys

quiquealonso8 avatar Oct 16 '20 17:10 quiquealonso8

gmaps does kind of "work" on Colab if you are alright making an export.html file per @pbugnion's post above: #281 (comment)

After making the file, you just need to run:

import IPython
IPython.display.HTML(filename='export.html')

I tried the following block of code

!pip install gmaps
!pip install ipywidgets
!pip install widgetsnbextension
import gmaps
import ipywidgets as widgets
from ipywidgets.embed import embed_minimal_html
import IPython

API_KEY = 'AI...'
gmaps.configure(api_key=API_KEY)
new_york_coordinates = (40.75, -74.00)
fig = gmaps.figure(center=new_york_coordinates, zoom_level=12)
embed_minimal_html('export.html', views=[fig])
IPython.display.HTML(filename="export.html")

This came up:

Something went wrong authenticating with Google Maps. This may be because you did not pass in an API key, or the key you passed in was incorrect.

Check the browser console, look for errors that start with Google Maps API error and compare the message against the Google Maps documentation.

If you see InvalidKeyMapError, the key you passed in is invalid. If you see MissingKeyMapError, you have not passed your API key to jupyter-gmaps. Pass an API key by writing gmaps.configure(api_key="AI...").

Am I missing something?

fdq09eca avatar Nov 04 '20 20:11 fdq09eca

Something went wrong authenticating with Google Maps. This may be because you did not pass in an API key, or the key you passed in was incorrect.

Check the browser console, look for errors that start with Google Maps API error and compare the message against the Google Maps documentation.

If you see InvalidKeyMapError, the key you passed in is invalid. If you see MissingKeyMapError, you have not passed your API key to jupyter-gmaps. Pass an API key by writing gmaps.configure(api_key="AI...").


Am I missing something?

First, pass the API key. I don't know how IPython works, but, if you use a browser to display the export.html file, then as it said, check your browser console (Ctrl+Shift+J on Chromium), you should see the NotActivateAPI error. The problem here is you are trying to display your map as html web, so you should Enable the Google Maps JavaScript API to let Google knows about it.

xuanhaihust avatar Nov 14 '20 15:11 xuanhaihust

I ran these to install (from the terminal): pip install ipywidgets pip install widgetsnbextension

Then ran the code mentioned 2 posts above in Colab: import ipywidgets as widgets from ipywidgets.embed import embed_minimal_html import IPython embed_minimal_html('export.html', views=[fig]) IPython.display.HTML(filename="export.html")

And I got the figure to show in Colab.

pk-lucas-a avatar Sep 26 '21 19:09 pk-lucas-a