---
title: "Obtain list of contacts from several DEIMS ID's (in csv file)"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Obtain list of contacts from several DEIMS ID's (in csv file)}
  %\VignetteEngine{knitr::knitr}
  %\usepackage[UTF-8]{inputenc}
author: "Alessandro Oggioni, Paolo Tagliolato"
---

Starting from the [DEIMS-SDR "Advanced Search - Sites" interface](https://deims.org/search/sites), users can download a csv file of the sites. Some filters can be used for selecting sites based on countries, projects, Biome, etc. The list of selected sites can be downloaded in csv format.

This vignette begins with such a csv file, and shows how to:

1. Obtain contacts details, and spatial info for all sites (limited to 7 sites)
2. Display in a table
3. Prepare of map of those sites

## List of the contacts


```r
library(ReLTER)
library(dplyr)
library(sf)
library(leaflet)
site_results <- read.csv("./data/site_contacts_data.csv", sep = ";") %>%
  as_tibble() %>% 
  mutate(url = paste0("https://deims.org/", DEIMS.ID)) %>%
  top_n(10) %>%
  unique()

# contacts <- site_results$url %>%
#   purrr::map_dfr(.f = function(x) {
#     x %>% ReLTER::get_site_info(category = "Contacts") %>%
#       dplyr::select(title, uri, siteManager, geoCoord) %>%
#       tidyr::unnest()
#   }) %>%
#   dplyr::mutate(
#     site = paste0("[", title, "](", uri, ")"),
#     contact = paste0("[", name, "](mailto:", email, ")")
#   ) %>%
#   unique()
#})

contacts <- lapply(site_results$url, function(u) {
  contact_info <- ReLTER::get_site_info(u, c("Contacts", "Boundary"))
  sm <- as.data.frame(contact_info$siteManager)
  cntt <- data.frame(site = paste0("[", contact_info$title, "](", contact_info$uri, ")"),
                  contact = paste0("[", sm$name, "](mailto:", sm$email, ")"),
                  geoCoord = contact_info$geoCoord)
  return(cntt)
  })
contacts <- do.call(rbind, contacts)

# Contacts table
knitr::kable(contacts[, c("site", "contact")],
  #(contacts %>% dplyr::select(site, contact)),
  caption = "List of the contacts",
  booktabs = TRUE, longtable = TRUE
)
```



Table: List of the contacts

|site                                              |contact     |
|:-------------------------------------------------|:-----------|
|[Beatenberg - Switzerland](https://deims.org/f6a6b3e0-9a39-4fe3-8ae5-24d833b8ad26)|[](mailto:) |
|[Colognole TOS1 - Italy](https://deims.org/fdd9b462-d2a9-441a-80a1-f4e8947f5577)|[](mailto:) |
|[Jussy - Switzerland](https://deims.org/fa36576a-6409-41d4-96ae-67f2a3d7e085)|[](mailto:) |
|[Krkonose/Karkonosze - Czechia](https://deims.org/fbab0f16-f991-4608-bca2-d1d3b9e89507)|[](mailto:) |
|[Krofdorf - Germany](https://deims.org/f73a0f95-8fb0-4755-92fc-f4b0207f5fe4)|[](mailto:) |
|[Oulanka Research Station (Oulanka LTER) - Finland](https://deims.org/f81f30bb-6e2b-4a11-9b65-266fee2ae330)|[](mailto:) |
|[Salmopol - Poland](https://deims.org/ffdea94e-8148-4adf-8f64-c2d2289f242f)|[](mailto:) |

## Map of the sites


```r
site_results_geo <- st_as_sf(
      contacts,
      wkt = "geoCoord"
    )

listItaSitesMap <- leaflet(site_results_geo) %>%
  addTiles() %>%
  addCircleMarkers(
    data = site_results_geo,
    radius = 3,
    weight = 2,
    opacity = 0.5,
    fill = TRUE,
    fillOpacity = 0.2,
    popup = paste0(
      '<b>eLTER site: </b><br><a href="',
      site_results_geo$uri, '">', site_results_geo$title, '</a><br>',
      '<b>Contact:</b> <br><a href="mailto:', site_results_geo$email, '">',
      site_results_geo$name, '</a>'
    )
  )
listItaSitesMap
```

```
## Error in path.expand(path): invalid 'path' argument
```
