Skip to content

Commit

Permalink
Set shinytest for MetaShARK.
Browse files Browse the repository at this point in the history
  • Loading branch information
earnaud committed Aug 23, 2021
1 parent acd4349 commit 2d7e1a3
Show file tree
Hide file tree
Showing 13 changed files with 463 additions and 158 deletions.
56 changes: 40 additions & 16 deletions R/app_header.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,51 @@
assign("wip", .args$wip, main.env)

# Paths ====
wwwPaths <- system.file("resources", package = "MetaShARK")
wwwPaths <- paste(wwwPaths, dir(wwwPaths), sep = "/") |>
wwwPaths <- system.file("resources", package = "MetaShARK") |>
dir(full.names = TRUE) |>
as.list()
names(wwwPaths) <- basename(unlist(wwwPaths))

HOME <- if(isTRUE(getOption("shiny.testmode")))
system.file("../tests/testthat/app/tests/shinytest/test_data_package/", package = "MetaShARK") else
"~/dataPackagesOutput/emlAssemblyLine"
PATHS <- reactiveValues(
home = "~",
eal.dp = paste0("~/dataPackagesOutput/emlAssemblyLine/"),
eal.dp.index = paste0("~/dataPackagesOutput/emlAssemblyLine/index.txt"),
home = HOME,
eal.dp = sprintf(
"%s/",
HOME
),
eal.dp.index =sprintf(
"%s/index.txt",
HOME
),
eal.tmp = tempdir(),
resources = wwwPaths
)
dir.create(isolate(PATHS$eal.dp), recursive = TRUE, showWarnings = FALSE)
if(!isTRUE(getOption("shiny.testmode")))
dir.create(isolate(PATHS$eal.dp), recursive = TRUE, showWarnings = FALSE)
dir.create(isolate(PATHS$eal.tmp), recursive = TRUE, showWarnings = FALSE)

assign("PATHS", PATHS, envir = main.env)

# Sessionning ====

if (isTRUE(file.exists(isolate(PATHS$eal.dp.index)))) {
DP.LIST <- data.table::fread(isolate(PATHS$eal.dp.index), sep = "\t")
if(isTRUE(getOption("shiny.testmode"))) {
devmsg(tag = "test", "setting DP list")
DP.LIST <- data.frame(
creator = character(),
name = character(),
title = character(),
path = character(),
stringsAsFactors = FALSE
)
} else if (isTRUE(file.exists(isolate(PATHS$eal.dp.index)))) {
DP.LIST <- readDataTable(isolate(PATHS$eal.dp.index), sep = "\t")
DP.LIST$path <- DP.LIST$path |>
gsub(pattern = "//+", replacement = "/")
} else {
DP.LIST <- data.frame(
creator.orcid = character(),
creator = character(),
name = character(),
title = character(),
path = character(),
Expand All @@ -56,8 +76,8 @@
sapply(.files, function(.file) {
.info <- jsonlite::read_json(
sprintf(
"%s/%s.json",
.file,
"%s/%s.json",
.file,
basename(.file) |>
gsub(pattern = "_emldp$", replacement = "")
)
Expand All @@ -81,18 +101,25 @@
isolate(main.env$PATHS$eal.dp),
pattern = "_emldp$",
full.names = TRUE
) |> gsub(pattern = "//+", replacement = "/")
) |>
gsub(pattern = "//+", replacement = "/")
DP.LIST <- dplyr::filter(DP.LIST, path %in% .actual.index)

# save actual index
data.table::fwrite(DP.LIST, isolate(PATHS$eal.dp.index), sep = "\t")

assign("DP.LIST", DP.LIST, envir = main.env)
makeReactiveBinding("DP.LIST", env = main.env)

# Values ====
# DataONE nodes
.ENDPOINTS <- readDataTable(
wwwPaths$registeredEndpoints.txt
)

assign(
"VALUES",
reactiveValues(
dataone.endpoints = .ENDPOINTS,
thresholds = reactiveValues(
files.size.max = 500000
),
Expand All @@ -101,8 +128,6 @@
envir = main.env
)
# Formats ====
# DataONE nodes
.DATAONE.LIST <- data.table::fread(wwwPaths$dataoneCNodesList.txt)

# Taxa authorities
.TAXA.AUTHORITIES <- data.table::fread(wwwPaths$taxaAuthorities.txt)
Expand Down Expand Up @@ -142,7 +167,6 @@
"hh:mm:ss", "hh:mm", "mm:ss", "hh"
),
units = .units,
dataone.list = .DATAONE.LIST,
taxa.authorities = .TAXA.AUTHORITIES
),
envir = main.env
Expand Down
12 changes: 1 addition & 11 deletions R/app_server.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ server <- function(input, output, session) {
# get variables
args <- get("metashark.args", envir = .GlobalEnv)
main.env <- .globalScript(.args = args, envir = session$userData)
addResourcePath("media", system.file("media/", package = "MetaShARK"))

# Set user-specific data
assign(
Expand Down Expand Up @@ -61,17 +62,6 @@ server <- function(input, output, session) {

# Update values ====
invisible({
# DataONE nodes
.DATAONE.LIST <- if(!main.env$dev)
try(dataone::listFormats(dataone::CNode())) else
try(silent = TRUE)
if (class(.DATAONE.LIST) != "try-error") {
.DATAONE.LIST <- readDataTable(
isolate(main.env$PATHS$resources$dataoneCNodesList.txt)
)
isolate(main.env$dataone.list <- .DATAONE.LIST)
}

# Taxa authorities
.TAXA.AUTHORITIES <- if(!main.env$dev)
try(taxonomyCleanr::view_taxa_authorities()) else
Expand Down
4 changes: 3 additions & 1 deletion R/app_ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ ui <- function() {
# get app arguments
# main.env <- get("main.env", options()$metashark.env)

addResourcePath("media", system.file("media/", package = "MetaShARK"))

# prepare variable
.menu.width <- "250px"
# ShinyJS extension -- unused
Expand Down Expand Up @@ -46,7 +48,7 @@ ui <- function() {
h2("Loading..."),
shinydashboardPlus::loadingState(),
tags$img(
src = "media/sea_shark.png",
src = "media/sea_shark.png",
width = "473px",
height = "235px"
)
Expand Down
8 changes: 5 additions & 3 deletions R/eal_1_SelectDP.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ SelectDPUI <- function(id) {
textInput(
NS(id, "dp_name"),
"Data package name",
placeholder = paste0(Sys.Date(), "_project")
placeholder = "my_project"
),
textInput(
NS(id, "dp_title"),
Expand Down Expand Up @@ -304,8 +304,10 @@ SelectDP <- function(id, main.env) {
)

observeEvent(input$quick, {
req(input$dp_name %in% c("", paste0(Sys.Date(), "_project"))) # Do not change a yet changed name
if (input$quick) {
req(input$dp_name %in% c("", "my_project", paste0(Sys.Date(), "_project"))) # Do not change a yet changed name
if(isTRUE(getOption("shiny.testmode"))) {
updateTextInput(session, "dp_name", value = "my_project")
} else if (input$quick) {
updateTextInput(session, "dp_name", value = paste0(Sys.Date(), "_project"))
} else {
updateTextInput(session, "dp_name", placeholder = paste0(Sys.Date(), "_project"))
Expand Down
1 change: 1 addition & 0 deletions R/runMetashark.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ runMetashark <- function(...) {
)
})
} else if(isTRUE(args$use.test)) {
options("shiny.testmode" = TRUE)
shinyApp(ui = ui, server = server)
} else {
runApp(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"fill-Miscellaneous-additional.information-file": null,
"fill-Miscellaneous-methods-content": "<p><br><\/p>",
"fill-Miscellaneous-methods-file": null,
"fill-Miscellaneous-Miscs": null,
"fill-Miscellaneous-temporal_coverage": [
null,
null
Expand All @@ -38,7 +37,7 @@
"fill-SelectDP-dp_delete": 0,
"fill-SelectDP-dp_list": "",
"fill-SelectDP-dp_load": 0,
"fill-SelectDP-dp_name": "2021-08-16_project",
"fill-SelectDP-dp_name": "my_project",
"fill-SelectDP-dp_title": "",
"fill-SelectDP-license": "CCBY",
"fill-SelectDP-quick": true,
Expand Down Expand Up @@ -67,15 +66,13 @@
"settings-help-metacat-link": 0,
"settings-metacat_token": "",
"settings-orcid-help-link": 0,
"sidemenu": "upload",
"sn-checkbox-open-in-new-window": true,
"test_end": 0,
"upload": "upload",
"upload-action": "upload",
"upload-data": null,
"upload-dev": 0,
"upload-DP": "---",
"upload-endpoint": "PNDB (dev)",
"upload-endpoint": "cn",
"upload-metadata": null,
"upload-online_dp": "",
"upload-process": 0,
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions tests/testthat/app/tests/shinytest/app_launches.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
app <- ShinyDriver$new("../../")
app$snapshotInit("app_launches")

app$snapshot()
113 changes: 113 additions & 0 deletions tests/testthat/app/tests/shinytest/datafile_1.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
Id density_boats distance_coast percentage_turbidity nb_individual recorder min_t max_wind
ID1 0 7.083851986 1 1 13740 9 13
ID2 0 5.057419245 1 1 3760 11.7 15
ID3 0 14.81271925 1 1 17598 9 13
ID4 23.38130966 17.39474876 0 1 17607 12.8 24
ID5 0 13.8788222 1 1 17608 14.3 17
ID6 0 20.55593297 1 1 13733 20 17
ID7 0 5.228906117 1 1 10250 14.3 30
ID8 0 8.18336163 0.963336783 2 13740 11.7 15
ID9 0 14.77478497 1 1 13733 11.7 15
ID10 0 18.23789045 1 1 17573 9 13
ID11 0 30.97770737 0.934057759 2 17608 8.1 13
ID12 0 14.72135785 0 2 13733 8.1 13
ID13 0 26.97792869 1 1 17578 8.1 13
ID14 0 8.63834361 1 1 17329 11.7 15
ID15 23.42372625 2.371250707 0.611485317 2 17232 14.3 30
ID16 0 2.058590657 1 1 NA 11.7 15
ID17 0 14.5557442 1 1 11693 14.3 17
ID18 0 15.31628381 0.484376584 2 10250 14.2 9
ID19 22.68310089 18.12266606 1 1 13733 16.9 13
ID20 0 10.71630644 0.946424061 2 17608 NA NA
ID21 0 7.492501839 1 1 17608 14.3 30
ID22 0 2.455167732 1 1 17578 8.1 13
ID23 0 0.215005092 0.619357094 2 17608 13.3 0
ID24 0 20.5942275 0.530977409 2 17573 12.8 24
ID25 0 0.00565931 1 1 10250 9 13
ID26 0 4.61669024 1 1 3760 8.1 13
ID27 0 0.650746944 1 1 13289 NA NA
ID28 11.55094443 4.256523462 0.534748923 2 17608 17.4 15
ID29 25.29249263 0.333785924 0 3 11693 16.9 13
ID30 5.659985665 3.927116342 1 1 17578 16.9 13
ID31 0 0.011314137 0 2 13740 20 17
ID32 0 6.724401426 0.262229612 3 17578 8.5 7
ID33 0 10.20546782 0.456408314 2 13676 17.8 13
ID34 0 0.005662514 1 1 13289 9 13
ID35 0 12.50424544 1 1 13733 13.3 0
ID36 41.24173899 0.028288543 0 2 17607 NA NA
ID37 0 0.707453733 0 2 13733 17.8 13
ID38 7.278017273 8.411585021 0.521433594 2 17601 17.4 15
ID39 26.46665163 3.174693 1 1 17598 11.7 15
ID40 21.65723654 8.846001472 0.672489759 2 17232 9 13
ID41 0 7.296088753 0.033790965 2 17601 9 13
ID42 0 0.848848396 0 3 17608 17.4 14
ID43 0 17.47693701 1 1 NA 8.1 13
ID44 0 8.040770102 1 1 17329 8.1 13
ID45 0 9.227200724 1 1 17607 8.1 13
ID46 0 4.089829166 0 1 17607 17.4 15
ID47 16.24258106 12.9081546 0.519677866 2 17232 14.3 17
ID48 0 28.17682685 0 3 13733 14.2 9
ID49 0 11.13752122 0.568145458 2 17329 12.8 24
ID50 0 12.15482119 0.744442086 2 13676 17.4 14
ID51 0 1.075147125 0.126547756 2 17329 17.8 13
ID52 0 0.639429606 0.318501019 3 17573 17.8 13
ID53 0 11.34563151 1 1 13289 9 13
ID54 0 6.070721358 1 1 11693 8.1 13
ID55 0 2.534940304 1 1 3760 NA NA
ID56 0 0 1 1 17608 14.9 13
ID57 23.6734518 9.73526417 1 1 13733 14.9 13
ID58 22.77461434 2.30834512 0 2 3760 17.4 15
ID59 0 9.034849513 1 1 NA 14.3 30
ID60 0 1.61299451 1 1 17598 8.1 13
ID61 0 1.550212164 1 1 17601 8.1 13
ID62 16.6417688 0.198064626 1 1 13676 13.3 0
ID63 0 0.147167035 0.503759276 2 13740 14.9 13
ID64 0 1.126075147 1 1 17329 14.2 9
ID65 0 1.166213768 0.486555056 2 10250 17.4 14
ID66 0 37.17890687 0.241246715 3 11693 12.3 11
ID67 0 1.01318843 1 1 NA 11.7 15
ID68 0 14.97426034 0.513275979 3 17578 8.5 7
ID69 0 0.050933786 1 1 10250 13.3 0
ID70 0 1.60733488 1 1 11693 13.3 0
ID71 0 0.15274085 0.616607437 2 11693 14.9 13
ID72 0 4.745186863 0.427826338 3 17578 14.9 13
ID73 0 0.005658029 1 1 13289 17.4 15
ID74 20.10097018 1.120479882 1 1 17329 9 13
ID75 0 1.833512535 1 1 11693 9 13
ID76 0 1.964892412 1 1 3760 14.9 13
ID77 0 1.024508972 1 1 17598 13.3 0
ID78 13.02008677 2.446206116 0 2 17601 17.8 13
ID79 0 5.849408836 0.506514891 2 17601 12.3 11
ID80 0 0.82602546 1 1 17607 20 17
ID81 0 6.632335465 1 1 13733 17.8 13
ID82 9.774097667 2.083923212 0.147137616 2 17329 17.4 14
ID83 0 0.843046283 1 1 17598 11.7 15
ID84 0 17.16743054 1 1 3760 9 13
ID85 0 2.347816248 1 1 17607 13.3 0
ID86 0 2.089467724 1 1 17608 8.1 13
ID87 14.70497236 1.782279054 1 1 17329 8.1 13
ID88 0 1.828267391 1 1 10250 8.1 13
ID89 19.54258479 2.829334541 1 1 3760 14.3 30
ID90 22.89867383 0.50376408 1 1 17573 14.3 30
ID91 0 7.486419194 1 1 13676 14.2 9
ID92 0 4.612337295 1 1 17601 11.7 15
ID93 0 20.34521788 1 1 17232 11.7 15
ID94 0 13.69731259 0.558754442 2 13289 14.3 17
ID95 0 0.481041313 0.601822162 2 17607 14.3 17
ID96 0 19.55721647 0.856473518 3 17232 16.9 13
ID97 0 9.467489106 1 1 10250 17.4 15
ID98 0 22.78746039 0.460271388 3 11693 14.3 30
ID99 0 8.380520951 0.769578171 2 17607 9 13
ID100 32.43763517 0.486507892 0.297384797 4 17573 12.3 11
ID101 39.87341993 18.47598574 0.377696294 3 17329 NA NA
ID102 0 1.482655198 0.420523151 2 17598 NA NA
ID103 0 1.188455008 1 1 13289 8.1 13
ID104 0 2.981949867 1 1 17232 13.3 0
ID105 6.048310547 0.06224536 1 1 17578 17.4 14
ID106 0 0.067957866 1 1 17232 17.4 14
ID107 0 0.305516266 0 1 17598 17.4 14
ID108 0 1.375212224 0.512278187 2 17601 20 17
ID109 23.18323585 0.045282164 0.355925541 2 13676 17.4 14
ID110 0 0 0.599181014 2 17232 13.3 0
ID111 0 0.050922259 1 1 17329 14.9 13
ID112 0 0.763920326 1 1 13740 13.3 0
Loading

0 comments on commit 2d7e1a3

Please sign in to comment.