I'm kind of new with R/RStudio and I'm trying to make a flexdashboard, with rmarkdown, for my organization combining a geospatial object file (country districts boundaries) and other xlsx file. But at the end I get the pandoc errors 1455 and 251. Notice that when I run every chunk independently, they work fine in preview mode in sourse area.

The problem appears right at the very end when I try to knit the document in html format. I use windows 10 and have local R version 4.3.1 (2023-06-16 ucrt) run under RStudio version RStudio 2023.09.0+463 "Desert Sunflower" Release (b51c81cc303d4b52b010767e5b30438beb904641, 2023-09-25).

Actions taken after reading others on this and other pages:

  • I have divided the chunks into smaller ones.
  • Established the self.contained=FALSE argument in the chunk where the leaflet map is placed.
  • Downloaded newest PANDOC version 3.1.11 for windows and place the argument to call it in an independent chunk.
  • Isolated the code part that is generating the errors.

Here the reproducible part of the code mentioned:

---
title: "OBSERVATORIO DATOS"
output: 
  flexdashboard::flex_dashboard:
    logo: LogoReducido.png
    orientation: column
    vertical_layout: fill
    
---
CLASIFICACIÓN
=======================================================================

Column
-----------------------------------------------------------------------

```{r, setup, include=FALSE}
rmarkdown::find_pandoc(version = '3.1.11')
```

```{r, libraries, echo=FALSE, message=FALSE, warning=FALSE}

setwd("C:/Users/BigO/Documents/Reporteria")

library(tmap) 
library(dplyr)  
library(tidyverse) 
library(tidycensus)
library(readxl) 
library(knitr) 
library(kableExtra)
library(leaflet) 
library(leaflet.extras)
library(leafpop)
library(raster) 
library(rgdal)
library(gridExtra) 
library(janitor) 
library(sf) 
library(viridis) 
library(osrm) 
library(htmltools)
library(htmlwidgets)
library(DT)
library(sp)
library(magrittr)
library(pdftools)
library(rJava)
library(tabulizer)
library(purrr)
library(tidyr)
library(tibble)
library(PDE)
library(googlesheets4)
library(googledrive)
library(plotrix)
library(formattable)
```

```{r, calculo, echo=FALSE, message=FALSE, warning=FALSE}

map_distritos <- geojsonio::geojson_read("C:/Users/BigO/Documents/Panama_District_Boundaries_2016.geojson", what = "sp")

names(map_distritos@data)[5] <- "MUNICIPIO"
map_distritos$MUNICIPIO[35] <- "Santa Fe Darien"

municipios_pob <- read_excel("C:/Users/BigO/Documents/Reporteria/Poblacion_sexo.xlsx", sheet = "TABLA1")
municipios_pob <- municipios_pob[-c(27, 83),]

map_dist_pob <- sp::merge(map_distritos, municipios_pob, by.x = "MUNICIPIO", by.y= "MUNICIPIO")

map_dist_pob1 <- st_as_sf(map_dist_pob)
```

### MAPA

```{r, mapa, echo=FALSE, includefig.height=4, fig.width=10, message=FALSE, warning=FALSE, results='asis', self.contained=FALSE, tidy=TRUE, tidy.opts=list(comment = FALSE)}

map_metro <- map_dist_pob1 %>% dplyr::filter(CANT_POB>=250000) %>% arrange(desc(CANT_POB)) %>% mutate(CLASIF = "Metropolitano")
map_urbano <- map_dist_pob1 %>% dplyr::filter(CANT_POB %in% 40001:250000) %>% arrange(desc(CANT_POB)) %>% mutate(CLASIF = "Urbano")
map_semiurbano <- map_dist_pob1 %>% dplyr::filter(CANT_POB %in% 40000:6001) %>% arrange(desc(CANT_POB)) %>% mutate(CLASIF = "Semiurbano")
map_rural <- map_dist_pob1 %>% dplyr::filter(CANT_POB %in% 6000:1) %>% arrange(desc(CANT_POB)) %>% mutate(CLASIF = "Rural")

map_dist_pob2 <- rbind(map_metro, map_urbano, map_semiurbano, map_rural)

pal <- colorNumeric("YlOrRd", domain = map_dist_pob2$CANT_POB)

#pal <- colorNumeric("viridis", NULL)

rr <- tags$div(
  HTML('<a href:" "> Fuente: IGNTG, INEC Y AMUPA <br> Elaboracion: AMUPA </a>')
)

label_1 <- paste0(
  "Provincia:", map_dist_pob2$PROVINCIA, "<br>",
  "Municipio:", map_dist_pob2$MUNICIPIO, "<br>",
  "Población:", map_dist_pob2$CANT_POB, "<br>",
  "Clasificación:", map_dist_pob2$CLASIF, "<br>") %>%
  lapply(htmltools::HTML)

leaflet(map_dist_pob2) %>%
  addTiles() %>%
  addPolygons(data = map_dist_pob2 , stroke = TRUE, smoothFactor = 0.3, fillOpacity = 1, color = "black", weight = 1, opacity = 0.5, fillColor = ~pal(CANT_POB), label = ~label_1) %>% 
  setView(lat = 8.457803, lng = -79.818159, zoom = 7) %>%
  addLegend("bottomright",pal = pal, values = ~CANT_POB, title = "Población", opacity = 1.0) %>%
  addControl(rr, position = "bottomleft") %>%
  addResetMapButton()
```

Sorry for my english. Thanks in advance!

0

There are 0 best solutions below