# code to prepare `ppo_filters` dataset goes here
#' This is how I got the data for the different filters that can be used when
#' doing a query. Can put it in a function because the way I get the webpage
#' doesn't work if I do for some reason. Can't use regular web scrapping because
#' the data generated by the angular.js isn't in the source code.
#' all code commented so it doesn't run, but you can rerun if you want to update
#' the .Rdata file
# #-- get the data from the left list of filters on http://www.plantphenology.org
# driver <- RSelenium::rsDriver(browser = "firefox", verbose = FALSE)
# driver$client$navigate("http://www.plantphenology.org")
# elements <- driver$client$findElements(value = "//eui-singleselect")
# #-- make a list of data.frame with the filters
# ppo_filters <- vapply(elements, \(e){
# txt <- strsplit(e$getElementText()[[1]], "\n")[[1]]
# txt <- matrix(unlist(strsplit(txt, " \\(")), ncol = 2, byrow = TRUE)
# txt[,2] <- gsub("[^0-9]","", txt[,2])
# fld <- gsub("'","", e$getElementAttribute("field")[[1]])
# out <- data.frame(x = txt[,1], y = strtoi(txt[,2]))
# colnames(out) <- c(fld, "nObs")
# list(`names<-`(list(x = out), fld))
# }, list("")) |>
# unlist(recursive = FALSE)
# #-- cleanup
# driver$client$close()
# #--- without this, the server doesn't stop
# system("taskkill /im java.exe /f", intern = FALSE, ignore.stdout = FALSE)
# rm(list = c("driver", "elements"))
# #--- since only one source is ever used
# ppo_filters$source <- ppo_filters$source[1,]
#
# #-- add a column to help filter by status later
# ppo_filters$mapped_traits$status <- gsub(".*(present).*|.*(absent).*","\\1\\2", ppo_filters$mapped_traits$mapped_traits)
#
# #-- then use ppo_terms to get the description value :
# ppo_terms_data <- ppo_terms(TRUE, TRUE)
# ppo_filters$mapped_traits <- merge(ppo_filters$mapped_traits,
# ppo_terms_data,
# by.x = "mapped_traits", by.y = "label")
# #--- goes from 119 rows in ppo_terms_data to 85 rows. The traits "lost" return nothing anyway.
# colnames(ppo_filters$mapped_traits)[1] <- "label"
# #--- reorder so it can be subsetted with [,1:3] when returning the data.frame
# # with ppo_get_terms
# ppo_filters$mapped_traits <- ppo_filters$mapped_traits[, c("termID", "label", "definition", "uri", "nObs", "status")]
# ppo_filters$mapped_traits[,c("ObjectProperty_termID", "ObjectProperty_termID1","ObjectProperty_termID2")] <-
# stringi::stri_extract_all_regex(ppo_filters$mapped_traits$definition,"P?PO:[0-9]+", simplify = TRUE)[,3:5]
# #-- removing genus since it's only the top 50 and not all available ones.
# ppo_filters$genus <- NULL
# #-- save data
# usethis::use_data(ppo_filters, overwrite = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.