html - 传单 map 不会在浏览器中呈现

标签 html r leaflet r-markdown

我有一个使用 Leaflet 的 map ,它在 r markdown 的 html 输出中工作,但是当我在 Google 或 IE 中打开 html 时, map 不会呈现。 Ggmap 工作正常,但我更喜欢交互式 map 。有什么想法吗?

```{r setup, include=FALSE}
knitr::opts_chunk$set(
  echo = FALSE,
  warning = FALSE,
  message = FALSE,
  comment=NA,
  fig.height=7,
  fig.width = 9)
```

```{r Libraries}
library(leaflet)
library(ggmap)
```

Plot map with leaflet package.    
```{r Leaflet}
#using leaflet
Pin <- data.frame(t(c(ID=1,Lat=-27.474176,Lng=153.024901)))

Bne2 <- leaflet() %>%
  addTiles()  %>%
  addMarkers(data=Pin)
Bne2

```

Plot map with ggmap package.   
```{r Ggmap}
#using ggmap
Sa2 <- data.frame(t(c(ID=1,Lat=-27.474176,Lng=153.024901)))
Brisbane <- get_map("Brisbane,Australia",zoom=11)

BNE <- ggmap(Brisbane)+
  geom_point(data=Sa2,aes(x=Lng,y=Lat),color="black",size=3)

plot(BNE)

```

最佳答案

我遇到了同样的问题,它似乎与未在浏览器中呈现的默认图 block 有关。但是,我不知道为什么会这样。

所以有几个选项是

  1. 更改图 block 层 ( https://leaflet-extras.github.io/leaflet-providers/preview/ )
  2. 使用不同的映射包。在这里,我演示了用于绘制交互式 Google map 的 googleway 包

```{r Libraries}
library(leaflet)
library(ggmap)
library(googleway)
```

Plot map with leaflet package.    
```{r Leaflet}
#using leaflet
Pin <- data.frame(t(c(ID=1,Lat=-27.474176,Lng=153.024901)))

Bne2 <- leaflet() %>%
  addTiles(urlTemplate = 'http://{s}.tile.opentopomap.org/{z}/{x}/{y}.png')  %>%
  addMarkers(data=Pin)
Bne2

```

Plot map with ggmap package.   
```{r Ggmap}
#using ggmap
Sa2 <- data.frame(t(c(ID=1,Lat=-27.474176,Lng=153.024901)))
Brisbane <- get_map("Brisbane,Australia",zoom=11)

BNE <- ggmap(Brisbane)+
  geom_point(data=Sa2,aes(x=Lng,y=Lat),color="black",size=3)

plot(BNE)

```

Plot map with googleway
```{r googleway}
## you need an api key to use google maps
mapKey <- 'your_api_key'

google_map(key = mapKey) %>%
    add_markers(data = Pin)

```

这三个都在 Chrome 中工作

enter image description here

关于html - 传单 map 不会在浏览器中呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44895440/

相关文章:

javascript - 分离和附加 div 作为 jquery 中的对话框

javascript - HTML:监听输入的*所有*变化,而不仅仅是键盘驱动的变化?

r - 以 polylineDecorator 为例的传单插件和传单代理

javascript - 使 Leaflet 侧边栏 div 在标记单击时处于事件状态,反之亦然

r - 二项式数据的预测栅格范围超出 0-1(包 'raster')

javascript - Leaflet MarkerCluster - 如何检查集群是否将被蜘蛛化(即具有 maxZoom 级别)?

javascript - 为什么 .size() 不能按我想象的方式工作?

php - Wordpress - 试图删除顽固的标题

r - 计算莫兰 I 测试空间自相关的问题

r - 使用 RGoogleDocs 时如何防止密码泄露?