Skip to content

Commit

Permalink
Develop (#250)
Browse files Browse the repository at this point in the history
* fix rsconnect deployment and renv.lock
  • Loading branch information
GuidoMaggio authored Aug 28, 2023
1 parent 25db486 commit e5a5ba5
Show file tree
Hide file tree
Showing 13 changed files with 515 additions and 491 deletions.
1 change: 0 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@
^app\.R$
^man-roxygen$
^\.github$
^deploy$
^rsconnect$
2 changes: 2 additions & 0 deletions .Rprofile
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# renv::settings$ignored.packages(c("devtools", "Covid19Mirai"), persist = FALSE)
source("renv/activate.R")

25 changes: 14 additions & 11 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
name: CI-CD
# renv with GitHub actions: https://rstudio.github.io/renv/articles/ci.html#github-actions

# Triggered on push and pull request events, schedule for data update
on:
push:
pull_request:
schedule:
# every day at 21 UTC
- cron: "0 21 * * *"
name: CI-CD

# renv with GitHub actions: https://rstudio.github.io/renv/articles/ci.html#github-actions


jobs:
CI-CD:
Expand All @@ -29,6 +31,7 @@ jobs:
R_KEEP_PKG_SOURCE: yes

steps:

- name: Checkout repo
uses: actions/checkout@v3

Expand All @@ -39,16 +42,16 @@ jobs:
# Enable RStudio Package Manager to speed up package installation
use-public-rspm: true

- name: Activate renv and restore packages with cache
uses: r-lib/actions/setup-renv@v2

# - name: Install system dependencies
# env:
# RHUB_PLATFORM: linux-x86_64-ubuntu-gcc
# # This is not taken care of (yet) by r-lib/actions/setup-renv
# # Package distro used to get the distro for the used ubuntu-latest
# run: |
# Rscript -e "renv::install('r-hub/sysreqs')"
# sysreqs=$(Rscript -e "cat(sysreqs::sysreq_commands('DESCRIPTION'))")
# sudo -s eval "$sysreqs"
# Rscript -e "install.packages(c('remotes', 'distro'))"
# while read -r cmd
# do
# eval sudo $cmd
# done < <(Rscript -e 'writeLines(with(distro::distro(), remotes::system_requirements(id, short_version)))')

- name: Activate renv and restore packages with cache
uses: r-lib/actions/setup-renv@v2

Expand Down Expand Up @@ -77,7 +80,7 @@ jobs:
git push origin
- name: Deploy to shinyapps.io
# Continuous deployment only for pushes to the main / master branch
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
# if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
env:
SHINYAPPS_ACCOUNT: ${{ secrets.SHINYAPPS_ACCOUNT }}
SHINYAPPS_TOKEN: ${{ secrets.SHINYAPPS_TOKEN }}
Expand Down
12 changes: 7 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,22 @@ Imports:
grid,
leaflet,
leaflet.extras,
rgdal,
shinycssloaders,
lubridate,
sp,
markdown,
scales,
COVID19,
grDevices,
pkgload,
rlang,
zoo
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.2.1
RoxygenNote: 7.2.3
Suggests:
testthat,
pkgload,
rsconnect
rsconnect,
spelling,
testthat (>= 3.0.0),
sf,
packrat
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export(get_timeseries_global_data)
export(get_timeseries_province_data)
export(get_timeseries_single_data)
export(lab_percent)
export(load_countries_data_map)
export(lw_vars_calc)
export(merge_pop_data)
export(new_total_colors)
Expand Down
5 changes: 3 additions & 2 deletions R/run_app.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
#' @export
#' @importFrom shiny shinyApp
#' @importFrom golem with_golem_options
#'
run_app <- function(
...
) {
with_golem_options(
app = shinyApp(
ui = app_ui,
ui = app_ui,
server = app_server
),
),
golem_opts = list(...)
)
}
139 changes: 0 additions & 139 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -307,146 +307,7 @@ new_total_colors <- c(
"new" = "#ea8b5b"
)

#' load countries data
#' @param destpath path to file
#'
#' @returns countries shapefile
#' @export
load_countries_data_map <- function(destpath = system.file("./countries_data", package = "Covid19Mirai")){
# Resource https://www.naturalearthdata.com/downloads/50m-cultural-vectors/50m-admin-0-countries-2/
url <- "https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/50m/cultural/ne_50m_admin_0_countries.zip"
zip_path <- file.path(destpath,"ne_50m_admin_0_countries.zip")
dsn_path <- file.path(destpath, "ne_50m_admin_0_countries")

if (!file.exists(zip_path)) {
download.file(url = url, destfile = zip_path)
unzip(zip_path, exdir = dsn_path)
}

countries <- rgdal::readOGR(dsn = dsn_path,
layer = "ne_50m_admin_0_countries",
encoding = "utf-8", use_iconv = T,
verbose = FALSE)
assign_new_level = function(countrymap , lev, from, to, regexpress = FALSE) {
if (regexpress) {
if (!any(grepl(from, as.character(countrymap[[lev]]))))
stop("wrong expression, not present in map: ", from)
from = grep(from, as.character(countrymap[[lev]]), value = TRUE)
}
if (!any(countrymap[[lev]] == from))
stop("wrong name, not present in map: ", from)
levels(countrymap[[lev]])[levels(countrymap[[lev]])==from] <- to
countrymap[[lev]][countrymap[[lev]] == from] = to
countrymap
}
#rename continents
countries = assign_new_level(countries, "CONTINENT", "North America", "Northern America")
countries = assign_new_level(countries, "CONTINENT", "South America", "LatAm & Carib.")
#rename NAME, i.e. countries
#countries = assign_new_level(countries, "NAME", "Macao", "Macau")
#countries = assign_new_level(countries, "NAME", "Macao", "Macau")
countries = assign_new_level(countries, "NAME", "Macedonia", "North Macedonia")
countries = assign_new_level(countries, "NAME", "Czechia", "Czech Republic")
countries = assign_new_level(countries, "NAME", "Dominican Rep.", "Dominican Republic")
countries = assign_new_level(countries, "NAME", "United Kingdom", "UK")
countries = assign_new_level(countries, "NAME", "United States of America", "USA")
countries = assign_new_level(countries, "NAME", "United Arab Emirates", "UAE")
countries = assign_new_level(countries, "NAME", "^St-Barth", "St. Barth", regexpress = TRUE)
countries = assign_new_level(countries, "NAME", "Faeroe Is.", "Faeroe Islands")
countries = assign_new_level(countries, "NAME", "Bosnia and Herz.", "Bosnia and Herzegovina")
countries = assign_new_level(countries, "NAME", "Vatican", "Vatican City")
countries = assign_new_level(countries, "NAME", "St. Vin. and Gren.", "St. Vincent Grenadines")
countries = assign_new_level(countries, "NAME", "Dem. Rep. Congo", "Republic of the Congo")
#countries = assign_new_level(countries, "NAME", "Central African Rep.", "CAR")
countries = assign_new_level(countries, "NAME", "Ivoire", "Cote d'Ivoire", regexpress = TRUE)
countries = assign_new_level(countries, "NAME", "St-Martin", "St Martin")
countries = assign_new_level(countries, "NAME", "Cayman Is.", "Cayman Islands")
countries = assign_new_level(countries, "NAME", "Eq. Guinea", "Equatorial Guinea")
countries = assign_new_level(countries, "NAME", "Central African Rep.", "CAR")
countries = assign_new_level(countries, "NAME", "eSwatini", "Eswatini")
countries = assign_new_level(countries, "NAME", "Cabo Verde", "Cape Verde")
countries = assign_new_level(countries, "NAME", "S. Sudan", "South Sudan")
countries = assign_new_level(countries, "NAME", "Fr. Polynesia", "French Polynesia")
countries = assign_new_level(countries, "NAME", "Antigua and Barb.", "Antigua and Barbuda")
countries = assign_new_level(countries, "NAME", "Cook Is.", "Cook Islands")
countries = assign_new_level(countries, "NAME", "Falkland Is.", "Falkland Islands")
countries = assign_new_level(countries, "NAME", "U.S. Virgin Is.", "U.S. Virgin Islands")

countries
}

#' load countries data to match with get_datahub
#' @param destpath path to file
#'
#' @returns countries shapefile
#' @noRd
load_countries_datahub_map <- function(destpath = system.file("./countries_data", package = "Covid19Mirai")){
# Resource https://www.naturalearthdata.com/downloads/50m-cultural-vectors/50m-admin-0-countries-2/
url <- "https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/50m/cultural/ne_50m_admin_0_countries.zip"
zip_path <- file.path(destpath,"ne_50m_admin_0_countries.zip")
dsn_path <- file.path(destpath, "ne_50m_admin_0_countries")

if (!file.exists(zip_path)) {
download.file(url = url, destfile = zip_path)
unzip(zip_path, exdir = dsn_path)
}

countries <- rgdal::readOGR(dsn = dsn_path,
layer = "ne_50m_admin_0_countries",
encoding = "utf-8", use_iconv = T,
verbose = FALSE)
assign_new_level = function(countrymap , lev, from, to, regexpress = FALSE) {
if (regexpress) {
if (!any(grepl(from, as.character(countrymap[[lev]]))))
stop("wrong expression, not present in map: ", from)
from = grep(from, as.character(countrymap[[lev]]), value = TRUE)
}
if (!any(countrymap[[lev]] == from))
stop("wrong name, not present in map: ", from)
levels(countrymap[[lev]])[levels(countrymap[[lev]])==from] <- to
countrymap[[lev]][countrymap[[lev]] == from] = to
countrymap
}
#rename continents
countries = assign_new_level(countries, "CONTINENT", "North America", "Northern America")
countries = assign_new_level(countries, "CONTINENT", "South America", "LatAm & Carib.")
#rename NAME, i.e. countries
#countries = assign_new_level(countries, "NAME", "Macao", "Macau")
#countries = assign_new_level(countries, "NAME", "Macao", "Macau")
countries = assign_new_level(countries, "NAME", "Macedonia", "North Macedonia")
countries = assign_new_level(countries, "NAME", "Czechia", "Czech Republic")
countries = assign_new_level(countries, "NAME", "Dominican Rep.", "Dominican Republic")
countries = assign_new_level(countries, "NAME", "United Kingdom", "UK")
countries = assign_new_level(countries, "NAME", "United States of America", "USA")
#countries = assign_new_level(countries, "NAME", "United Arab Emirates", "UAE") # now has new name
countries = assign_new_level(countries, "NAME", "^St-Barth", "St. Barth", regexpress = TRUE) # not needed but ok
countries = assign_new_level(countries, "NAME", "Faeroe Is.", "Faeroe Islands")
countries = assign_new_level(countries, "NAME", "Bosnia and Herz.", "Bosnia and Herzegovina")
countries = assign_new_level(countries, "NAME", "Vatican", "Vatican City")
countries = assign_new_level(countries, "NAME", "St. Vin. and Gren.", "St. Vincent Grenadines")
countries = assign_new_level(countries, "NAME", "Dem. Rep. Congo", "Republic of the Congo")
#countries = assign_new_level(countries, "NAME", "Central African Rep.", "CAR")
countries = assign_new_level(countries, "NAME", "Ivoire", "Cote d'Ivoire", regexpress = TRUE)
countries = assign_new_level(countries, "NAME", "St-Martin", "St Martin")
countries = assign_new_level(countries, "NAME", "Cayman Is.", "Cayman Islands")
countries = assign_new_level(countries, "NAME", "Eq. Guinea", "Equatorial Guinea")
countries = assign_new_level(countries, "NAME", "Central African Rep.", "Central African Republic")
countries = assign_new_level(countries, "NAME", "eSwatini", "Swaziland")
countries = assign_new_level(countries, "NAME", "Cabo Verde", "Cape Verde")
countries = assign_new_level(countries, "NAME", "S. Sudan", "South Sudan")
countries = assign_new_level(countries, "NAME", "Fr. Polynesia", "French Polynesia")
countries = assign_new_level(countries, "NAME", "Antigua and Barb.", "Antigua and Barbuda")
countries = assign_new_level(countries, "NAME", "Cook Is.", "Cook Islands")
countries = assign_new_level(countries, "NAME", "Falkland Is.", "Falkland Islands")
countries = assign_new_level(countries, "NAME", "U.S. Virgin Is.", "U.S. Virgin Islands") # new name
countries = assign_new_level(countries, "NAME", "St. Kitts and Nevis", "Saint Kitts and Nevis" ) # new name
countries = assign_new_level(countries, "NAME", "Principe", "Sao Tome and Principe", regexpress = TRUE )
countries = assign_new_level(countries, "NAME", "N. Mariana Is.", "Northern Mariana Islands")
countries = assign_new_level(countries, "NAME", "Marshall Is.", "Marshall Iselands")
countries = assign_new_level(countries, "NAME", "St. Pierre and Miquelon", "St. Pierre and Miquelon")

countries
}

#' Sort type by max
#'
Expand Down
7 changes: 6 additions & 1 deletion deploy/deploy-shinyapps.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ rsconnect::setAccountInfo(
Sys.getenv("SHINYAPPS_TOKEN"),
Sys.getenv("SHINYAPPS_SECRET")
)

# to be added since rsconnect >1
options(rsconnect.packrat = FALSE)

rsconnect::deployApp(
account = "miraisolutions",
appName = "Covid19",
forceUpdate = TRUE
forceUpdate = TRUE, # to be added since rsconnect >1
quarto = FALSE # to be added since rsconnect >1
# exclude hidden files and renv directory (if present)
# appFiles = setdiff(list.files(), "renv")
)
Loading

0 comments on commit e5a5ba5

Please sign in to comment.