-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathhome_info.qmd
More file actions
106 lines (89 loc) · 2.52 KB
/
home_info.qmd
File metadata and controls
106 lines (89 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
---
title: Practical Info
subtitle: Venue, address, travel and contact information
toc: false
number-sections: false
sidebar: false
code-tools: false
format: html
freeze: false
---
```{r}
#| eval: true
#| include: false
library(yaml)
library(here)
library(leaflet)
library(readxl)
#' Get location data from YAML into a list and data.frame
#' @param y YAML data
#' @param loc Name of location
#' @return List with description and data.frame with map data
#'
get_info <- function(y, loc) {
loc <- tolower(loc)
if (loc %in% names(y)) {
info <- y[[loc]]
if (!is.null(info$description)) {
d <- info$description
} else {
d <- NULL
}
if (!is.null(info$map)) {
m <- do.call(rbind, lapply(info$map, function(x){
required_fields <- c("label", "marker_icon", "marker_color", "lat", "lon", "popup")
missing_fields <- setdiff(required_fields, names(x))
if (length(missing_fields) > 0) {
stop(paste("Missing fields:", paste(missing_fields, collapse = ", ")))
}
as.data.frame(x)
}))
} else {
m <- NULL
}
return(list(description = d, map = m))
} else {
message(paste0("Location ", loc, " not found in the data"))
return(NULL)
}
}
# Set location in _quarto.yml
loc <- sapply(unlist(strsplit(yaml::read_yaml(here("_quarto.yml"))$location,";|,")),trimws)
l <- yaml::yaml.load_file(here("info.yml"))
```
## Location
```{r}
#| echo: false
#| eval: true
#| results: "asis"
cat("\n::: {.panel-tabset}\n")
for (i in seq_along(loc)) {
p <- loc[i]
cat(paste0("\n### ", tools::toTitleCase(p), "\n"))
idata <- get_info(l, p)
if (!is.null(idata)) {
if (!is.null(idata$map)) {
dfr1 <- idata$map
dfr1$popup <- gsub(";|; ", "<br>", dfr1$popup)
dfr2 <- dfr1[complete.cases(dfr1$lat, dfr1$lon), ]
cat(knitr::knit_child(input = "assets/_child-info.qmd", envir = environment(), quiet = TRUE))
cat("\n")
}
if (!is.null(idata$description)) {
cat("\n", idata$description)
}
}else{
cat("No additional information is provided.")
}
cat("\n")
}
cat(":::\n")
```
## Contact
This workshop is run by the **National Bioinformatics Infrastructure Sweden
(NBIS)**. NBIS is a platform at [SciLifeLab](https://www.scilifelab.se/)
(Science For Life Laboratory) and the Swedish node of
[Elixir](https://elixir-europe.org/).
If you would like to get in touch with us regarding this workshop, please contact us at **edu.trr [at] nbis.se**.
***
{height="26px"}