如何在colab的R笔记本中显示交互式传单地图

How to display interactive leaflet map in R notebook in colab

我无法在中绘制交互式地图 colab

解决方法(静态图像)在第二个单元格中。

我希望在 r-leaflet 中得到答案。

相关blog

我带着这个 answer/workaround - colab

中的第三个单元格
if (system.file(package = "leaflet") == '') {
  install.packages("leaflet")
}
if (system.file(package = "htmlwidgets") == '') {
  install.packages("htmlwidgets")
}
if (system.file(package = "IRdisplay") == '') {
  install.packages("IRdisplay")
}

library(leaflet)
library(htmlwidgets)
library(IRdisplay)

m = leaflet() %>% 
#addTiles() 
addTiles(urlTemplate = "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png") # colab compatibility

saveWidget(m, 'demo1.html', selfcontained = TRUE)

IaminColab<-TRUE

if(IaminColab){  # does not work in jupyter
  demo<-readLines("demo1.html")
  demo<-gsub("%","%25",demo)
  demo<-gsub("#","%23",demo)
  demo<-gsub("\"","%22",demo)
  demo<-gsub("'" ,"%27",demo)
  demo<-gsub("\n" ,"",demo)
  demo<-paste(demo, collapse="")
  display_html(paste0('<iframe src=',"\"data:text/html;charset=UTF-8,",demo," \" height=\"300\" width=\"500\"></iframe>") )
} else { # does not work in colab
  display_html('<iframe src="demo1.html" width="500" height ="300"></iframe>')
}

来源:
Convert HTML to data:text/html link using JavaScript