【发布时间】:2021-03-02 08:06:13
【问题描述】:
我正在尝试在xaringan 演示文稿中包含一张传单地图。网上有几个这样的例子,包括this 演示文稿。
当我的同事测试下面的最小示例时,他们在幻灯片 2 上得到了一个交互式地图,正如预期的那样。但是当我运行它时,我看不到地图,而只是看到一个带有 html 代码的滑块。
这适用于我同事的机器:
---
title: "Testing leaflet"
output:
xaringan::moon_reader:
lib_dir: libs
nature:
highlightStyle: github
highlightLines: true
countIncrementalSlides: false
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(message = FALSE, warning = FALSE)
```
```{r out.width='100%', fig.height=6}
library(leaflet)
library(dplyr)
leaflet() %>% addTiles() %>% setView(lat = 30.2621, lng = -97.7382, zoom = 17)
```
这是我在 xaringan 幻灯片上看到的屏幕截图:
这是显示在幻灯片框中的实际 html 代码:
<div id="htmlwidget-627abe20cf1eb0297594" style="width:100%;height:432px;" class="leaflet html-widget"></div>
<script type="application/json" data-for="htmlwidget-627abe20cf1eb0297594">{"x":{"options":{"crs":{"crsClass":"L.CRS.EPSG3857","code":null,"proj4def":null,"projectedBounds":null,"options":{}}},"calls":[{"method":"addTiles","args":["//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",null,null,{"minZoom":0,"maxZoom":18,"tileSize":256,"subdomains":"abc","errorTileUrl":"","tms":false,"noWrap":false,"zoomOffset":0,"zoomReverse":false,"opacity":1,"zIndex":1,"detectRetina":false,"attribution":"© <a href=\"http://openstreetmap.org\">OpenStreetMap<\/a> contributors, <a href=\"http://creativecommons.org/licenses/by-sa/2.0/\">CC-BY-SA<\/a>"}]}],"setView":[[30.2621,-97.7382],17,[]]},"evals":[],"jsHooks":[]}</script>
因为这适用于其他人的机器,所以我认为问题一定与我的设置有关。我试过重新启动 RStudio 并重新安装 xaringan,但在那之后我不知道要检查什么。任何建议将不胜感激!
这是我的会话信息,以防可能有助于诊断问题:
> sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.7
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
locale:
[1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_4.0.3 rsconnect_0.8.16 htmltools_0.5.1.1 tools_4.0.3 xaringan_0.19 yaml_2.2.1
[7] rmarkdown_2.6 knitr_1.30 xfun_0.20 digest_0.6.27 rlang_0.4.10 evaluate_0.14
【问题讨论】:
-
我看到的和你一样,但我找不到原因。我怀疑这是某些软件包更新中引入的错误:我会比较您的系统和您的同事之间的软件包版本,看看有什么不同,并尝试安装旧版本(使用
remotes::install_version()),看看您是否可以找到导致问题。 (最好在文档本身中运行sessionInfo(),以防它获取不同的包。) -
感谢@user2554330 的这个建议!你是对的:我的同事有
rmarkdown_2.5,而我有rmarkdown_2.6。安装 v2.5 解决了问题!