Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将保存的传单小部件插入Rmarkdown HTML输出_R_R Markdown_Htmlwidgets_R Leaflet - Fatal编程技术网

如何将保存的传单小部件插入Rmarkdown HTML输出

如何将保存的传单小部件插入Rmarkdown HTML输出,r,r-markdown,htmlwidgets,r-leaflet,R,R Markdown,Htmlwidgets,R Leaflet,我创建传单小部件并将其保存在本地: 库(htmlwidgets) 图书馆(单张) 图书馆(sf) shp=st_read(“/path/to/some/shapefile.shp”) m=shp%>% 传单()%>% addProviderTiles(提供程序$CartoDB.Positron)%>% 设置视图(lng=-70,纬度=40,缩放=11) saveWidget(m,“m.html”) 现在我想在Rmarkdown块中加载此小部件: --- title: "Title" autho

我创建传单小部件并将其保存在本地:

库(htmlwidgets)
图书馆(单张)
图书馆(sf)
shp=st_read(“/path/to/some/shapefile.shp”)
m=shp%>%
传单()%>%
addProviderTiles(提供程序$CartoDB.Positron)%>%
设置视图(lng=-70,纬度=40,缩放=11)
saveWidget(m,“m.html”)
现在我想在Rmarkdown块中加载此小部件:

---
title: "Title"
author: "author"
date: "5/8/2020"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

etc etc etc

```{r}
function_that_loads_widget("m.html")
```

etc etc etc

我尝试了
htmltools::includeHTML()
,但这使整个HTML输出成为一个大部件。不显示报告的文本

我意识到我可以将创建传单小部件的代码直接放在Rmarkdown块中,但我不想这样做。

knitr::include_url()似乎是解决方案。这适用于我的blogdown帖子

```{r, out.width="100%"}
knitr::include_url("url_of_html", height="1080px")
```

saveWidget
并没有真正做到它的名字所暗示的。它实际上更像是
renderWidget
。我认为你无法从中恢复小部件。如果要保存R对象,请使用
saveRDS()
save()
,然后使用
readRDS()
load()
读回该对象。为什么不
source
直接创建小部件的代码?@MartinSchmelzer(非OP):我的用例是每天运行一个R脚本来更新PNG和地图,并将它们上传到S3。我也有一个使用blogdown构建的博客,它引用了这些PNG,这样我就不必每天重建博客了。源代码意味着必须重建博客,并每天推送到github托管。