在 rmarkdown 文件的 html 输出中的 for 循环内渲染 tmap 映射

问题描述

我正在尝试在 rmarkdown 文件中使用 for 循环生成 tmap。它们不会显示在 html 输出中。我在其他地方使用 tagList 函数阅读可能有所帮助,但在我的情况下没有并返回错误(我可能做错了)。有什么想法吗?

这种使用 tmap 的尝试不起作用。我收到此错误:“as.character.default(x) 中的错误:没有将此 S4 类强制转换为向量的方法

html <- list()

for (i in 1:4) {

 
tmap_mode("view")

html <- c(html,list(h3(paste0("Carte_Dept_",i)),tm_basemap(leaflet::providers$Stamen.Toner) +
  tm_shape(communes_dept_pct) +
  tm_fill("pct",palette = "-RdYlGn",style ="quantile",title ="% bât. FG",alpha = 0.6,popup.vars = c("Commune:" = "nom","% bât. FG:" = "pct"),group = "Communes") +
  tm_borders(col = "black",lwd = 0.5) +
  tm_shape(spdf) +
  tm_dots(size = 0.05,col = "red",title = "Bâtiments FG",cluster = T,popup.vars = c("Type bâtiment:" = "tr002_type_batiment_description","Classe GES: " = "classe_estimation_ges","Nom méthode:" = "nom_methode_dpe"),group = "Bâtiments F-G") +
  tm_shape(spdf2) +
  tm_dots(size = 0.05,shape = 21,col = "Domaine de travaux",title = "Artisans RGE",legend.show = F,cluster = F,popup.vars = c("Nom:" = "Nom de l'entreprise","Adresse: " = "Adresse","Ville:" = "Ville","Domaine:" = "Domaine de travaux","Effectif:" = "Tranche d'effectif salarié de l'établissement (INSEE)"),group = "Artisans RGE")
          )
  )
}

tagList(html)

然而,这确实有效,使用最简单的传单地图:

html <- list()

for (i in 1:4) {

html <- c(html,leaflet(communes_Occitanie_pct) %>%   addProviderTiles('Stamen.Toner') %>%
                setView(lng = 1.54,lat = 43.7,zoom = 7)
  
          )
  )
}

tagList(html)

不过我想使用 tmap,所以任何建议都可以帮助...

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...