Я пытаюсь использовать концепцию из здесь в автоматическом режиме, но карты не отображаются.Включенный HTML выглядит хорошо:
Минимальный воспроизводимый пример: Для генерации HTML см. Ниже или.
---
title: "Test"
author: "SQC"
date: "11 Juli 2019"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(leaflet)
save_path <- paste0("C:/Temp/SO-question/")
i <- 2
```
# Title level 1
This works
```{r, echo = FALSE, results='asis'}
htmltools::includeHTML(paste0(save_path, "helper_map_", i, ".html"))
```
But this does not
```{r, echo = FALSE, results='asis'}
for (i in 2:3) {
htmltools::includeHTML(paste0(save_path, "helper_map_", i, ".html"))
}
```
Где ошибка?Есть идеи?
Воспроизводимый пример с созданием карт
Создайте три файла в "C: / Temp / SO-question" (тогда все будет работатьбез изменений):
- render_hmtl.R
- report_include_html.Rmd
- helper_map_html.Rmd
- helper_table_html.Rmd
Различные файлы выглядят следующим образом:
render_hmtl.R
save_path <- paste0("C:/Temp/SO-question/")
load_path <- save_path
ranges <- paste0("section_", c(1:3))
cat("render html parts...\n")
for (i in 2:length(ranges)) {
rmarkdown::render(paste0(load_path, 'helper_map_html.Rmd'),
output_dir = save_path,
output_file = paste0("helper_map_", i, ".html"),
encoding = "UTF-8", quiet = T)
rmarkdown::render(paste0(load_path, 'helper_table_html.Rmd'),
output_dir = save_path,
output_file = paste0("helper_table_", i, ".html"),
encoding = "UTF-8", quiet = T)
}
cat("render html for comparison", paste(ranges, collapse = ", "), "...\n")
rmarkdown::render(paste0(load_path, 'report_include_html.Rmd'),
output_dir = save_path,
output_file = "report_include_html.html",
encoding = "UTF-8", quiet = T)
report_include_html.Rmd
---
title: "Test"
author: "SQC"
date: "11 Juli 2019"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(leaflet)
```
# Title level 1
This is an R Markdown document.
## Title level 2 (tab) {.tabset}
### Title level 3 (tab) {.tabset}
```{r, echo = FALSE, results='asis'}
for (i in 2:length(ranges)) {
cat(paste0("#### Title level 4 `r ",
ranges[i], "` vs. `r ", ranges[i - 1], "` {.tabset}\n"))
cat("##### Map\n")
htmltools::includeHTML(paste0(save_path, "helper_map_", i, ".html"))
cat("##### Tabelle\n")
htmltools::includeHTML(paste0(save_path, "helper_table_", i, ".html"))
}
```
### Title level 3 (tab) {.tabset}
```{r, echo = FALSE, results='asis'}
for (i in 2:length(ranges)) {
cat(paste0("#### `r ", ranges[i], "` vs. `r ", ranges[i - 1], "` {.tabset}\n"))
cat("##### Map\n")
htmltools::includeHTML(paste0(save_path, "helper_map_", i, ".html"))
cat("##### Tabelle\n")
htmltools::includeHTML(paste0(save_path, "helper_table_", i, ".html"))
}
```
helper_map_html.Rmd
---
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
```{r, fig.width=8.4, fig.height=7}
leaflet() %>%
addTiles() %>%
addProviderTiles(providers$OpenStreetMap, group = "OSM") %>%
addProviderTiles(providers$Stamen.TonerLite, group = "Toner Lite") %>%
addLayersControl(baseGroups = c("OSM", "Toner Lite")) %>%
addCircleMarkers(lat = 47, lng = 9, popup = ranges[i])
```
helper_table_html.Rmd
---
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
```{r}
DT::datatable(data.frame(x = 1, y = ranges[i], stringsAsFactors = FALSE),
rownames = FALSE)
```
(Этот вопрос возник из здесь )