在 R 中的reveal.js 演示文稿中看不到传单地图图块?

菲利波兰多

介绍:

我正在尝试将传单地图嵌入到 RMarkdown 文件中的revealjs 演示文稿中。我下面的示例非常接近,但它是 (1) 缺少图块,(2) 没有显示弹出窗口,以及 (3) 图例和字体太大了!

我不太关心代码块现在的样子。我计划在results = "hide"我的最终产品中使用幻灯片选项。

提前致谢!

可重现的例子:

---
title: "My Presentation"
author: Me
date: 2017-06-23
output:
    revealjs::revealjs_presentation:
        theme: black

---

## Loading in necessary packages:
```{r}
library(dplyr)
library(sp)
library(rgdal)
library(rgeos)
library(RColorBrewer)
library(classInt)
library(leaflet)
library(htmlwidgets)
```

## Defining our data:
```{r}
lat <- c(45.51158000, 45.50431159, 45.496539)
lon <- c(-122.548056, -122.54775, -122.54788)
no2 <- c(17.37, 25.61, 24.69)

dta <- data.frame(lat, lon, no2)
colnames(dta) <- c("lat","lon","no2")
```

## Create layer of spatial points:
```{r}
points <- SpatialPointsDataFrame(data.frame(x=dta$lon, y=dta$lat), data = data.frame(dta$no2))

plotclr <- (brewer.pal(7, "RdYlGn"))
class <- classIntervals(dta$no2, n = 7, style = "fixed", fixedBreaks = c(0,5,10,15,20,25,30))
colcode <- findColours(class, rev(plotclr))
plot(points, col=colcode, pch=19)

pop1<-paste0("<b>NO2:</b> ", dta$no2, " ppb", 
         "<br /> <b>Lat:</b> ", dta$lat, 
         "<br /> <b>Lon:</b> ", dta$lon) 
```

## Creating the leaflet map:
```{r}
no2_map <-leaflet()%>%
  addTiles('http://{s}.tiles.wmflabs.org/bw-mapnik/{z}/{x}/{y}.png') %>%
  addCircleMarkers(data=points, color = "black", radius = dta$no2, fillColor = colcode, fillOpacity=0.7, weight=1, popup=pop1) %>%
  addLegend(position = "bottomright", colors = rev(plotclr), labels = rev(c("30","25","20","15","10","5","0")), opacity = 0.9, title = "NO2 (ppb)")
```

---
```{r}
no2_map

saveWidget(no2_map, file="map.html")

```
伊万桑切斯

不幸的是,reveal.js 和 Leaflet 不能很好地配合使用,并且带有地图的幻灯片可能缺少图层。这是因为 Leaflet 无法识别用作地图容器的 DOM 元素的大小,因为reveal.js 动态调整所有元素的大小。

最简单的解决方法是在带有 Leaflet 地图的幻灯片中刷新页面。您还可以尝试延迟调用map.invalidateSize()(通过setTimeout()在纯 Javascript 中使用)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章