library(ggplot2)
scale_fill_msf <- function(...) {
ggplot2:::manual_scale(
"fill",
values = c(
"MSF" = "#D02327",
"OCA" = "#EF5423",
"OCB" = "#FFC70A",
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(sf) | |
library(DBI) | |
library(duckdb) | |
# sf object | |
nc <- st_read(system.file("shape/nc.shp", package = "sf")) | |
nc_crs <- st_crs(nc) | |
# write it to local gpkg | |
path_gpkg <- here::here("local.gpkg") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tab2_init <- TRUE | |
observeEvent(input$tabs, { # input$tabs is the menu input | |
if (all(input$tabs == "tab2", tab2_init)) { | |
# change to false so it won't run again | |
tab2_init <<- FALSE | |
# call server module | |
tab2Server("id", ...) | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
library(magrittr) | |
# images for picker input stored in www/img/ from the root app directory | |
imgs <- fs::dir_ls("www/img") %>% stringr::str_remove("www/") # remove www/ from filepath | |
img_name <- fs::path_file(imgs) %>% fs::path_ext_remove() # get image name without extension | |
select_choice_img <- function(img, text) { | |
shiny::HTML(paste( | |
tags$img(src=img, width=30, height=22), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
library(magrittr) | |
library(ggplot2) | |
library(officer) | |
ui <- fluidPage( | |
sidebarLayout( | |
sidebarPanel( | |
sliderInput("obs", "Number of observations:", min = 10, max = 500, value = 100), | |
actionButton("add_plot", "Add to ppt"), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Add custom circle legend to leaflet map | |
#' | |
#' To be used alongside \code{leaflet::addCircleMarkers} | |
#' | |
#' @param map a leaflet map | |
#' @param title title of the legend | |
#' @param range vector of numeric values you want to scale the legend to (same vector used with addCircleMarkers) | |
#' @param scaling_fun the scaling function used with addCircleMarkers to scale circle radii appropriately for leaflet | |
#' @param color stroke color | |
#' @param weight stroke width in pixels |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(leaflet) | |
world <- rnaturalearth::ne_countries(returnclass = "sf") | |
pal <- colorFactor("Dark2", levels = unique(world$continent)) | |
leaflet(world) %>% | |
setView(10, 15, zoom = 3) %>% | |
addMapPane(name = "polygons", zIndex = 410) %>% | |
addMapPane(name = "maplabels", zIndex = 420) %>% # higher zIndex rendered on top |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# OSM tile with no labels | |
osm_nolabels <- "https://tiles.wmflabs.org/osm-no-labels/{z}/{x}/{y}.png" | |
# OSM humanitarian tile (just for ref) | |
osm_hot <- "http://a.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png" | |
# if you a mapping a choropleth with polygons, this will render place labels above the polygons | |
leaflet() %>% | |
addMapPane(name = "polygons", zIndex = 410) %>% | |
addMapPane(name = "maplabels", zIndex = 420) %>% # higher zIndex rendered on top |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9 | |
sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/' | |
sudo apt update | |
sudo apt install r-base | |
sudo apt install libcurl4-openssl-dev libssl-dev libxml2-dev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sys.setlocale("LC_TIME", "fr_FR.UTF-8") |
NewerOlder