pbugnion / gmaps

Google maps for Jupyter notebooks
https://jupyter-gmaps.readthedocs.io/en/stable/
Other
760 stars 146 forks source link

Colab not displaying maps #281

Open RandomForestRanger opened 6 years ago

RandomForestRanger commented 6 years ago

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?

pbugnion commented 6 years ago

Thanks for raising this.

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

RandomForestRanger commented 6 years ago

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.

pbugnion commented 6 years ago

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:

RandomForestRanger commented 6 years ago

Understood and agreed on all points. Thanks Pascal.

pbugnion commented 6 years ago

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

DakotaHoosier commented 6 years ago

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 commented 6 years ago

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?

pbugnion commented 6 years ago

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

And yes, you can save the output as html.

frank-yifei-wang commented 5 years ago

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? ;)

pbugnion commented 5 years ago

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

I am not in any way affiliated with Google.

aiban commented 5 years ago

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')
nicolabc commented 4 years ago

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?

quiquealonso8 commented 4 years ago

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

fdq09eca commented 4 years ago

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?

xuanhaihust commented 4 years ago

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.

pk-lucas-a commented 3 years ago

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.