在Google Colab平台上的Jupyter Notebook中显示/渲染HTML文件

时间:2018-07-29 02:31:13

标签: python google-maps jupyter-notebook google-colaboratory

我正在使用Google Colab使用Python 3.0创建地图,并且已经使用底图进行了创建。接下来,我尝试使用Google地图创建类似的地图。我找到了两个python软件包,即gmaps和gmplot。似乎gmaps需要使用Google API,但gmplot不需要,因此我正在使用gmplot。

使用gmplot,我可以创建文件“ my_map.html”,如果将其下载到本地桌面,则可以在浏览器中打开并正确查看地图。

但是,我希望在笔记本计算机输出单元中查看地图,而不下载到本地计算机。下图是我尝试过的屏幕截图...没有错误,但也没有显示。
screenshot

是否有一些命令如%matplotlib inline需要执行才能显示输出单元格中文件的内容?还是有更好的解决方案

3 个答案:

答案 0 :(得分:1)

尝试使用文件的完整路径:/content/my_map.html

代码应为:

import IPython
IPython.display.HTML(filename='/path/to/your/filename')

答案 1 :(得分:0)

如果html包含位于colab或您(映射)的Google驱动器中的图像,则此解决方案不适用于我:

IPython.display.HTML('<img src="/content/elmo_1.jpg">') # can't find image 
IPython.display.HTML('<img src="/content/gdrive/My Drive/elmo_1.jpg">') # can't find image  
IPython.display.HTML('<img src="/content/gdrive/My%20Drive/elmo_1.jpg">') # can't find image  

但是,它可以使用标准网址:

IPython.display.HTML('<img src="https://github.com/blablabla/elmo_1.jpg?raw=1">') 

答案 2 :(得分:0)

请尝试以下代码:

from IPython.display import IFrame
IFrame(src='path/to/your/filename.html', width=900, height=600)

它确实为我工作。 :)