knitr::opts_chunk$set( collapse = TRUE, comment = "#>", warning = FALSE, message = FALSE )
This annex shows an interactive and searchable version of the results given by
climaemet::aemet_stations()
as of r format(Sys.Date(),"%d %b %Y")
:
library(climaemet) library(reactable) library(mapSpain) library(leaflet) library(crosstalk) library(sf) library(dplyr) df_init <- aemet_stations() labs <- esp_codelist %>% select(cpro, ccaa.shortname.es, prov.shortname.es) %>% distinct() %>% select(cpro, provincia = prov.shortname.es) # Data frame for labels df <- df_init %>% mutate( provincia = gsub("STA.", "SANTA", provincia), cpro = esp_dict_region_code(provincia, destination = "cpro") ) %>% select(-provincia) %>% left_join(labs) %>% select(-cpro) %>% relocate(provincia, .before = 1) %>% arrange(provincia, nombre) statns_data <- df %>% mutate( latitud = round(latitud, 6), longitud = round(longitud, 6) ) %>% SharedData$new(group = "stations") labels <- sprintf( "<strong>%s</strong><br/ ><i>%s</i><br/>indicativo: %s<br/>indsinop: %s", df$nombre, df$provincia, df$indicativo, df$indsinop ) %>% lapply(htmltools::HTML) map <- leaflet( width = "100%", height = "480px", elementId = "station-map", data = statns_data ) %>% addProviderEspTiles("IGNBase", group = "IGN Base") %>% addProviderEspTiles("PNOA", group = "Satellite (PNOA)") %>% setView(-3.6810800, 40.3070700, zoom = 5) %>% addMarkers(popup = labels, lat = df$latitud, lng = df$longitud) %>% addEasyButton(easyButton( icon = "fa-crosshairs", title = "Zoom to Level 1", onClick = JS( "function(btn, map){ map.setView([40.3070700, -3.6810800], 5); }" ) )) %>% addLayersControl( baseGroups = c("IGN Base", "Satellite (PNOA)"), options = layersControlOptions(collapsed = FALSE) ) tbl <- reactable( statns_data, selection = "multiple", onClick = "select", rowStyle = list(cursor = "pointer"), filterable = TRUE, searchable = TRUE, showPageSizeOptions = TRUE, striped = TRUE, groupBy = "provincia", defaultColDef = colDef(vAlign = "center"), paginationType = "jump", elementId = "station-table", columns = list( longitud = colDef(format = colFormat(separators = TRUE)), latitud = colDef(format = colFormat(separators = TRUE)) ) ) htmltools::browsable( htmltools::tagList(map, tbl) )
if (!require("sessioninfo")) { install.packages("sessioninfo") } sessioninfo::session_info()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.