diff --git a/.RData b/.RData
index 1103bfc..9703146 100644
Binary files a/.RData and b/.RData differ
diff --git a/NAMESPACE b/NAMESPACE
index c8029a0..445b4df 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -3,6 +3,8 @@
export(runMetashark)
export(write.text)
import(shiny)
+import(shinydashboard)
+import(shinydashboardPlus)
importFrom(EML,eml_validate)
importFrom(EML,get_unitList)
importFrom(EML,read_eml)
@@ -66,8 +68,6 @@ importFrom(shinyFiles,shinyFilesButton)
importFrom(shinyTree,get_selected)
importFrom(shinyTree,renderTree)
importFrom(shinyTree,shinyTree)
-importFrom(shinycssloaders,withSpinner)
-importFrom(shinydashboard,box)
importFrom(shinydashboard,dashboardBody)
importFrom(shinydashboard,dashboardHeader)
importFrom(shinydashboard,dashboardPage)
diff --git a/R/about-module.R b/R/about-module.R
index 648ef70..bcae16b 100644
--- a/R/about-module.R
+++ b/R/about-module.R
@@ -1,22 +1,73 @@
+#' @import shiny
+#'
+#' @noRd
+aboutUI <- function(id) {
+ ns <- NS(id)
+
+ fluidPage(
+ tags$h1("About MetaShARK dev team"),
+ HTML("MetaShARK is developped within the french Museum National
+ d'Histoire Naturelle / UMS Patrimoine Naturel / Pole
+ National de Biodiversite. Its development team is currently
+ composed of Elie Arnaud
+ (lead developer) and Yvan Le Bras (team director)."),
+
+ tags$h1("Thanks"),
+ HTML("MetaShARK could not be built without the help of those people:
+
+ Colin Smith (EDI, US) who collaborates with us since March
+ 2019, and currently provides us the EML Assembly Line tool.
+ "),
+
+ tags$h1("References"),
+ # Parties
+ tags$h2("LTER and EML Actors"),
+ tags$p("The following people and parties have worked upstream of
+ MetaShARK dev team to provide the fundamentals united in
+ the present tool."),
+ uiOutput(NS(id, "actors")),
+ # Informatics
+ tags$h2("Computer material"),
+ tags$p("The following references will lead the user to the source
+ of tools and methods reused in MetaShARK."),
+ uiOutput(NS(id, "informatics")),
+ # Sci litt
+ tags$h2("Literature"),
+ tags$p("MetaShARK is based on the following papers and articles
+ concerning mainly ecological metadata."),
+ uiOutput(NS(id, "ecology"))
+ )
+}
+
#' @title about
#'
#' @description server part of the about module.
-#'
+#'
#' @import shiny
-#'
+#'
#' @noRd
-about <- function(input, output, session) {
- ns <- session$ns
+about <- function(id) {
+ moduleServer(id, function(input, output, session) {
- .bibliography <- reactiveValues(
- actors = system.file("resources/bibliography-actors.bib", package = "MetaShARK"),
- informatics = system.file("resources/bibliography-informatics.bib", package = "MetaShARK"),
- ecology = system.file("resources/bibliography-ecology.bib", package = "MetaShARK"),
- misc = system.file("resources/bibliography-misc.bib", package = "MetaShARK")
- )
+ # misc = system.file("resources/bibliography-misc.bib", package = "MetaShARK")
- # use function
- output$actors <- renderBibliography(.bibliography$actors)
- output$informatics <- renderBibliography(.bibliography$informatics)
- output$ecology <- renderBibliography(.bibliography$ecology)
+ output$actors <- renderBibliography(
+ system.file(
+ "resources/bibliography-actors.bib",
+ package = "MetaShARK"
+ )
+ )
+ output$informatics <- renderBibliography(
+ system.file(
+ "resources/bibliography-informatics.bib",
+ package = "MetaShARK"
+ )
+ )
+ output$ecology <- renderBibliography(
+ system.file(
+ "resources/bibliography-ecology.bib",
+ package = "MetaShARK"
+ )
+ )
+ })
}
diff --git a/R/about-module_functions.R b/R/about-module_functions.R
index a0ebbaa..9ef854f 100644
--- a/R/about-module_functions.R
+++ b/R/about-module_functions.R
@@ -10,7 +10,7 @@
#' @importFrom utils capture.output
renderBibliography <- function(bib) {
.bib <- RefManageR::ReadBib(bib)
- RefManageR::NoCite(bib, "*")
+ RefManageR::NoCite(.bib, "*")
renderUI(
withProgress(message = "Loading bibtex ...", value = 0, {
diff --git a/R/aboutUI-module.R b/R/aboutUI-module.R
deleted file mode 100644
index c39e6d4..0000000
--- a/R/aboutUI-module.R
+++ /dev/null
@@ -1,40 +0,0 @@
-#' @import shiny
-#'
-#' @noRd
-aboutUI <- function(id) {
- ns <- NS(id)
-
- fluidPage(
- tags$h1("About MetaShARK dev team"),
- HTML("MetaShARK is developped within the french Museum National
- d'Histoire Naturelle / UMS Patrimoine Naturel / Pole
- National de Biodiversite. Its development team is currently
- composed of Elie Arnaud
- (lead developer) and Yvan Le Bras (team director)."),
-
- tags$h1("Thanks"),
- HTML("MetaShARK could not be built without the help of those people:
-
- Colin Smith (EDI, US) who collaborates with us since March
- 2019, and currently provides us the EML Assembly Line tool.
- "),
-
- tags$h1("References"),
- # Parties
- tags$h2("LTER and EML Actors"),
- tags$p("The following people and parties have worked upstream of
- MetaShARK dev team to provide the fundamentals united in
- the present tool."),
- uiOutput(NS(id, "actors")),
- # Informatics
- tags$h2("Computer material"),
- tags$p("The following references will lead the user to the source
- of tools and methods reused in MetaShARK."),
- uiOutput(NS(id, "informatics")),
- # Sci litt
- tags$h2("Literature"),
- tags$p("MetaShARK is based on the following papers and articles
- concerning mainly ecological metadata."),
- uiOutput(NS(id, "ecology"))
- )
-}
diff --git a/R/documentation-module.R b/R/documentation-module.R
index a6f1bb1..182e665 100644
--- a/R/documentation-module.R
+++ b/R/documentation-module.R
@@ -1,7 +1,6 @@
#' @import shiny
-#' @importFrom shinydashboard box
#' @importFrom shinyTree shinyTree
-#'
+#'
#' @noRd
docUI <- function(id) {
ns <- NS(id)
@@ -23,17 +22,16 @@ docUI <- function(id) {
shinyTree::shinyTree(
outputId = NS(id, "tree"),
search = TRUE,
- theme = "proton"
+ theme = "proton",
+ wholerow = TRUE,
+ multiple = FALSE
)
)
),
# display main panel
column(
7,
- div(
- id = "docPanel",
- uiOutput(NS(id, "doc"))
- )
+ uiOutput(NS(id, "doc"))
)
)
)
@@ -42,40 +40,45 @@ docUI <- function(id) {
#' @import shiny
#' @importFrom shinyTree renderTree get_selected
#' @importFrom jsonlite read_json unserializeJSON
-#'
+#'
#' @noRd
-documentation <- function(input, output, session) {
- ns <- session$ns
+documentation <- function(id) {
+ moduleServer(id, function(input, output, session) {
- # Load data ====
- withProgress(message = "Loading documentation.", {
- doc <- system.file("resources/doc_guideline.json", package = "MetaShARK") %>%
- jsonlite::read_json(simplifyVector = TRUE) %>%
- jsonlite::unserializeJSON()
- incProgress(0.5)
- tree <- system.file("resources/tree_guideline.json", package = "MetaShARK") %>%
- jsonlite::read_json(simplifyVector = TRUE) %>%
- jsonlite::unserializeJSON()
- incProgress(0.5)
- })
+ # Load data ====
+ doc <- system.file("resources/doc_guideline.json", package = "MetaShARK")
+ doc <- jsonlite::unserializeJSON(jsonlite::read_json(doc)[[1]])
- # UI render ====
+ tree <- system.file("resources/tree_guideline.json", package = "MetaShARK")
+ tree <- jsonlite::unserializeJSON(jsonlite::read_json(tree)[[1]])
- # render tree
- output$tree <- shinyTree::renderTree(tree)
+ # UI render ====
- # output selected node
- output$doc <- renderUI({
- tree.node <- shinyTree::get_selected(input$tree)
- validate(
- need(unlist(tree.node), "(Select an item first)")
- )
- path <- paste(c(attr(tree.node[[1]], "ancestry"), unlist(tree.node)), collapse = "/")
- doc.node <- followPath(doc, path)
- if ("annotation" %in% names(doc.node)) {
- doc.node$annotation
- } else {
- helpText("No content found at:", path)
- }
+ # render tree
+ output$tree <- shinyTree::renderTree({
+ tree
+ })
+
+ # output selected node
+ output$doc <- renderUI({
+ req("tree" %in% names(input))
+ tree.node <- get_selected(input$tree)
+ validate(
+ need(unlist(tree.node), "(Select an item first)")
+ )
+ path <- paste(
+ c(
+ attr(tree.node[[1]], "ancestry"),
+ unlist(tree.node)
+ ),
+ collapse = "/"
+ )
+ doc.node <- followPath(doc, path)
+ if ("annotation" %in% names(doc.node)) {
+ doc.node$annotation
+ } else {
+ helpText("No content found at:", path)
+ }
+ })
})
}
diff --git a/R/eal_1_SelectDP.R b/R/eal_1_SelectDP.R
index 73ec954..7aadde2 100644
--- a/R/eal_1_SelectDP.R
+++ b/R/eal_1_SelectDP.R
@@ -1,10 +1,10 @@
#' @import shiny
#' @importFrom shinyFiles shinyDirButton
-#'
+#'
#' @noRd
SelectDPUI <- function(id, main.env) {
ns <- NS(id)
-
+
# UI output
return(
fluidPage(
@@ -34,55 +34,27 @@ SelectDPUI <- function(id, main.env) {
filling. It will bring you to the next step."),
tags$li(tags$b("Previous:"), "click this to come back to one of
the previous steps. You can also use the steps", tags$span(
- icon("circle"),
- style = "color: dodgerblue;"
- ), " markers to get
+ icon("circle"),
+ style = "color: dodgerblue;"
+ ), " markers to get
to the desired step.")
)
)
)
),
- # Data package location ----
- # if (!isTRUE(server)) {
- # tagList(
- # fluidRow(
- # column(4,
- # if (isTRUE(server)) {
- # tags$b("Data Package will be saved in:")
- # } else {
- # shinyDirButton(
- # NS(id, "dp_location"),
- # "Choose directory",
- # "DP save location",
- # icon = icon("folder-open")
- # )
- # }
- # ),
- # column(8,
- # textOutput(NS(id, "dp_location")),
- # style = "text-align: left;"
- # ),
- # class = "inputBox"
- # ),
- # fluidRow(
- # tags$p("This is the location where your data packages will be
- # saved. A folder will be created, respectively named
- # after your input.")
- # )
- # )
- # } else {
- hr(),
# },
fluidRow(
# Load existing DP ----
- column(6,
+ column(
+ 6,
tags$h4("Edit existing data package",
style = "text-align:center"
),
uiOutput(NS(id, "dp_list"))
),
# Create DP ----
- column(6,
+ column(
+ 6,
tags$h4("Create new data package",
style = "text-align:center"
),
@@ -131,146 +103,130 @@ SelectDPUI <- function(id, main.env) {
#' @importFrom shinyjs enable disable onclick
#' @importFrom EMLassemblyline template_directories template_core_metadata
#' @importFrom jsonlite read_json unserializeJSON
-#'
+#'
#' @noRd
-SelectDP <- function(id, main.env){
+SelectDP <- function(id, full.id, main.env) {
moduleServer(id, function(input, output, session) {
- save.variable <- main.env$save.variable
- ns <- session$ns
-
+
+ # Help server
collapsible("usage")
-
+
# variable initialization ----
- rv <- reactiveValues(
- dp.location = main.env$PATHS$eal.dp,
- dp.name = character(),
- dp.title = character(),
- dp.list = NULL,
- dp.license = NULL
- )
-
- # DP location ----
- observeEvent(input$dp_location,
- {
- req(input$dp_location)
- rv$dp.location <- input$dp_location
- },
- label = "EAL1: input dp location"
- )
-
- # Render selected DP location
- output$dp_location <- renderText({
- rv$dp.location
- })
-
- # DP load ----
- # reset input if user comes back on this screen
- # fetch list of DP at selected location
- observeEvent({
- rv$dp.location
- main.env$SETTINGS$logged
- }, {
- # Build full DP list
- .dp.path <- gsub(
- "/+",
- "/",
- list.files(
- rv$dp.location,
- pattern = "_emldp$",
- full.names = TRUE
- )
- )
- .dp.list <- basename(.dp.path)
-
- # Note for local version: shall check for index (create it if not exists)
- # Index non-indexed DP
- if(length(.dp.list) > nrow(main.env$DP.LIST)){
- sapply(.dp.list, function(dp){
- .index <- main.env$DP.LIST
- if(!dp %in% .index$name){
- .tmp <- data.frame(
- creator.orcid = main.env$SETTINGS$user,
- name = dp,
- title = dp,
- path = gsub("/+","/", .dp.path[which(.dp.list == dp)]),
- stringsAsFactors = FALSE
- )
-
- .index <- rbind(.index, .tmp)
- assign("DP.LIST", .index, envir = main.env)
- }
- })
- }
-
- # Reduce list by property
- # - gather public and user's list = retrieve non-public, non-user DP
- .out <- main.env$DP.LIST %>%
- dplyr::filter(creator.orcid == "public") %>%
- dplyr::select(name) %>%
- lapply(paste, "(public)") %>%
- unlist
- if(isTRUE(main.env$SETTINGS$logged)){
- .out <- c(
- .out,
- main.env$DP.LIST %>%
- dplyr::filter(creator.orcid == main.env$SETTINGS$user) %>%
- dplyr::select(name) %>%
- lapply(paste, "(public)") %>%
- unlist
- )
- }
-
- if(length(.out) != 0)
- rv$dp.list <- sub("_emldp", "", .out) %>% unname
- else
- rv$dp.list <- NULL
- },
- label = "EAL1: build dp list"
- )
-
- # Render list of DP at selected location
- output$dp_list <- renderUI({
- validate(
- need(
- isTruthy(rv$dp.list),
- "No data package has been written."
+ # update list of DP at selected location
+ # observeEvent(
+ # {
+ # main.env$PATHS$eal.dp
+ # main.env$SETTINGS$logged
+ # },
+ # {
+ # # 1. Build full DP list
+ # # .dp.path <- gsub(
+ # # "/+",
+ # # "/",
+ # # list.files(
+ # # main.env$PATHS$eal.dp,
+ # # pattern = "_emldp$",
+ # # full.names = TRUE
+ # # )
+ # # )
+ # # dp.list <- basename(.dp.path)
+ #
+ # # 2. Index non-indexed DP
+ # # Note for local version: shall check for index (create it if not exists)
+ # # if (length(.dp.list) > nrow(main.env$DP.LIST)) {
+ # # sapply(.dp.list, function(dp) {
+ # # if (!dp %in% main.env$DP.LIST$name) {
+ # # main.env$DP.LIST <- rbind(
+ # # main.env$DP.LIST,
+ # # data.frame(
+ # # creator.orcid = main.env$SETTINGS$user,
+ # # name = dp,
+ # # title = dp,
+ # # path = gsub("/+", "/", .dp.path[which(.dp.list == dp)]),
+ # # stringsAsFactors = FALSE
+ # # )
+ # # )
+ # # }
+ # # })
+ # # }
+ #
+ # # 3. Reduce list by property
+ # # - gather public and user's list = retrieve non-public, non-user DP
+ # # .out <- main.env$DP.LIST %>%
+ # # dplyr::filter(creator.orcid == "public") %>%
+ # # dplyr::select(name) %>%
+ # # lapply(paste, "(public)") %>%
+ # # unlist()
+ # # if (isTRUE(main.env$SETTINGS$logged)) {
+ # # .out <- c(
+ # # .out,
+ # # main.env$DP.LIST %>%
+ # # dplyr::filter(creator.orcid == main.env$SETTINGS$user) %>%
+ # # dplyr::select(name) %>%
+ # # lapply(paste, "(public)") %>%
+ # # unlist()
+ # # )
+ # # }
+ #
+ # # if (length(.out) != 0) {
+ # # main.env$local.rv$dp.list <- sub("_emldp", "", .out) %>% unname()
+ # # } else {
+ # # main.env$local.rv$dp.list <- NULL
+ # # }
+ # },
+ # label = "EAL1: build dp list"
+ # )
+
+ # Save updated index
+ # observeEvent(main.env$DP.LIST, {
+ # data.table::fwrite(
+ # main.env$DP.LIST,
+ # isolate(main.env$PATHS$eal.dp.index),
+ # sep = "\t"
+ # )
+ # })
+
+ # Render DP list ====
+ observeEvent(main.env$local.rv$dp.list, {
+ output$dp_list <- renderUI({
+ validate(
+ need(
+ isTruthy(main.env$local.rv$dp.list),
+ "No data package has been written."
+ )
)
- )
- tagList(
- radioButtons(
- NS(id, "dp_list"),
- NULL,
- choiceNames = c("None selected", rv$dp.list),
- choiceValues = c("", rv$dp.list)
- ),
- actionButton(
- NS(id, "dp_load"),
- "Load",
- icon = icon("folder-open")
- ),
- actionButton(
- NS(id, "dp_delete"),
- "Delete",
- icon = icon("minus-circle"),
- class = "redButton"
- ),
- downloadButton(
- NS(id, "dp_download"),
- label = "Download .zip",
- icon = icon("file-download")
+ tagList(
+ radioButtons(
+ NS(full.id, "dp_list"),
+ NULL,
+ choiceNames = c("None selected", main.env$local.rv$dp.list),
+ choiceValues = c("", gsub(" \\(.*\\)$", "", main.env$local.rv$dp.list))
+ ),
+ actionButton(
+ NS(full.id, "dp_load"),
+ "Load",
+ icon = icon("folder-open")
+ ),
+ actionButton(
+ NS(full.id, "dp_delete"),
+ "Delete",
+ icon = icon("minus-circle"),
+ class = "redButton"
+ ),
+ downloadButton(
+ NS(full.id, "dp_download"),
+ label = "Download .zip",
+ icon = icon("file-download")
+ ),
+ tags$p(
+ "If you have handled manually some packages in",
+ isolate(main.env$PATHS$eal.dp),
+ ", some packages might not be listed here."
+ )
)
- )
- })
-
- # Save updated index ----
- observeEvent(main.env$DP.LIST, {
- data.table::fwrite(
- main.env$DP.LIST,
- isolate(main.env$PATHS$eal.dp.index),
- sep = "\t"
- )
+ })
})
-
+
# Manage DP download ----
output$dp_download <- downloadHandler(
filename = function() {
@@ -283,8 +239,8 @@ SelectDP <- function(id, main.env){
zipfile = file,
files = dir(
gsub(
- "/+",
- "/",
+ "/+",
+ "/",
dir(
".",
full.names = TRUE,
@@ -299,7 +255,7 @@ SelectDP <- function(id, main.env){
},
contentType = "application/zip"
)
-
+
# toggle Load and Delete buttons
observeEvent(input$dp_list,
{
@@ -314,14 +270,14 @@ SelectDP <- function(id, main.env){
shinyjs::disable("dp_download")
}
},
- label = "EAL1: UX hs"
+ label = "EAL1: [UX] dp buttons"
)
-
+
# DP create ----
# check name input
- rv$valid.name <- FALSE
+ main.env$local.rv$valid.name <- FALSE
output$dp_create <- renderUI({
- rv$valid.name <- FALSE
+ main.env$local.rv$valid.name <- FALSE
validate(
need(
nchar(input$dp_name) > 3,
@@ -334,21 +290,28 @@ SelectDP <- function(id, main.env){
),
need(
input$dp_name != ""
- && !(input$dp_name %in% rv$dp.list),
+ && !(input$dp_name %in% main.env$local.rv$dp.list),
"This name is already used: change either save directory or data package name."
),
need(
input$dp_title != ""
&& grepl("^[[:alnum:]\\ \\.,:_-]+$", input$dp_title),
- "This title has invalid character: use alphanumerics, or one of:
- ' ' '.' ',' ':' '_' '-' "
- # \" \", \".\", \",\", \":\", \"_\" or \"-\"."
+ "This title has invalid character: use alphanumerics, or one of:",
+ HTML(paste(
+ tags$code(' '),
+ tags$code('.'),
+ tags$code(','),
+ tags$code(':'),
+ tags$code('_'),
+ tags$code('-'),
+ sep = "  "
+ ))
)
)
- rv$valid.name <- TRUE
- return(actionButton(NS(id, "dp_create"), "Create"))
+ main.env$local.rv$valid.name <- TRUE
+ return(actionButton(NS(full.id, "dp_create"), "Create"))
})
-
+
observeEvent(input$quick,
{
req(input$dp_name %in% c("", paste0(Sys.Date(), "_project"))) # Do not change a yet changed name
@@ -360,236 +323,257 @@ SelectDP <- function(id, main.env){
},
label = "EAL1: quick"
)
-
- observeEvent(input$dp_name,
- {
- rv$dp.name <- input$dp_name
- },
- label = "EAL1: save dp name"
- )
-
- observeEvent(input$dp_title,
- {
- rv$dp.title <- input$dp_title
- },
- label = "EAL1: save dp title"
- )
-
- # license choice
- observeEvent(input$license,
- {
- rv$dp.license <- input$license
- },
- label = "EAL1: save dp license"
- )
-
+
+ main.env$local.rv$dp.name <- reactive(input$dp_name)
+ main.env$local.rv$dp.title <- reactive(input$dp_title)
+ main.env$local.rv$dp.license <- reactive(input$license)
+
# DP management - on clicks ----
# * Create DP ----
onclick("dp_create", {
req(input$dp_create)
- req(input$dp_name)
- req(rv$valid.name)
-
+ req(main.env$local.rv$dp.name())
+ req(main.env$local.rv$valid.name)
+
# variable operation - legibility purpose
- dp <- input$dp_name
- path <- paste0(rv$dp.location, dp, "_emldp")
- title <- input$dp_title
- license <- rv$dp.license
+ # dp <- main.env$local.rv$dp.name()
+
+ # title <- main.env$local.rv$dp.title()
+ # license <- main.env$local.rv$dp.license()
+ # quick <- input$quick
# verbose
withProgress(
{
# save in empty dedicated variable
- save.variable$emlal <- initReactive("emlal", savevar, main.env$EAL)
- save.variable$emlal$SelectDP$dp.name <- dp
- save.variable$emlal$SelectDP$dp.path <- path
- save.variable$emlal$SelectDP$dp.metadata.path <- paste(path, dp, "metadata_templates", sep = "/")
- save.variable$emlal$SelectDP$dp.data.path <- paste(path, dp, "data_objects", sep = "/")
- save.variable$emlal$SelectDP$dp.eml.path <- paste(path, dp, "eml", sep = "/")
- save.variable$emlal$SelectDP$dp.title <- title
- save.variable$emlal$quick <- input$quick
+ main.env$save.variable <- initReactive(
+ "emlal",
+ main.env$save.variable,
+ main.env
+ )
+ saveReactive(main.env)
+ # save.variable = main.env$save.variable,
+ # content = list(
+ # SelectDP = list(
+ # dp = dp,
+ # path = path,
+ # title = title,
+ # license = license,
+ # quick = quick
+ # )
+ # )
+ # )
incProgress(0.2)
- dir.create(path, recursive = TRUE)
- # add DP to index
- main.env$DP.LIST <- rbind(
- main.env$DP.LIST,
- data.frame(
- creator.orcid = main.env$SETTINGS$user,
- name = dp,
- title = title,
- path = path,
- stringsAsFactors = FALSE
- )
+ dir.create(
+ main.env$save.variable$SelectDP$dp.path,
+ recursive = TRUE
)
+ # add DP to index
+ # main.env$DP.LIST <- rbind(
+ # main.env$DP.LIST,
+ # data.frame(
+ # creator.orcid = main.env$SETTINGS$user,
+ # name = dp,
+ # title = title,
+ # path = path,
+ # stringsAsFactors = FALSE
+ # )
+ # )
incProgress(0.2)
-
+
# EAL template import
try(
EMLassemblyline::template_directories(
- save.variable$emlal$SelectDP$dp.path,
- save.variable$emlal$SelectDP$dp.name
+ main.env$save.variable$SelectDP$dp.path,
+ main.env$save.variable$SelectDP$dp.name
)
)
incProgress(0.2)
x <- try(
EMLassemblyline::template_core_metadata(
- save.variable$emlal$SelectDP$dp.metadata.path,
- license
+ main.env$save.variable$SelectDP$dp.metadata.path,
+ main.env$local.rv$dp.license()
)
)
incProgress(0.2)
-
+
if (class(x) != "try-error") {
- rv$dp.list <- c(rv$dp.list, dp)
+ main.env$local.rv$dp.list <- c(
+ main.env$local.rv$dp.list,
+ main.env$local.rv$dp.name()
+ )
main.env$EAL$page <- main.env$EAL$page + 1
- saveReactive(save.variable)
+ main.env$EAL$.load <- main.env$EAL$.load + 1
incProgress(0.2)
} else {
unlink(path, recursive = TRUE)
- save.variable <- initReactive(main.env = main.env$EAL)
+ main.env$save.variable <- initReactive(main.env = main.env$EAL)
incProgress(0.2)
- showNotification(x, type = "error")
+ showNotification(
+ x,
+ type = "error",
+ closeButton = TRUE,
+ duration = NULL
+ )
}
},
- message = paste("Creating:", path, "\n", sep = "")
+ message = paste(
+ "Creating:",
+ paste0(main.env$local.rv$dp.name(), "_emldp"),
+ "\n",
+ sep = ""
+ )
)
})
-
+
# * Load DP ----
shinyjs::onclick("dp_load", {
req(input$dp_list)
shinyjs::disable("dp_load")
# variable operation - legibility purpose
dp <- input$dp_list
- path <- paste0(rv$dp.location, dp, "_emldp")
-
+ path <- paste0(main.env$PATHS$eal.dp, dp, "_emldp")
+
# verbose
showNotification(
paste("Loading:", path, "\n", sep = ""),
type = "message"
)
-
+
# actions
- save.variable$emlal <- initReactive("emlal", savevar, main.env$EAL)
-
- .save.variable <- jsonlite::read_json(paste0(path, "/", dp, ".json"))[[1]] %>%
+ main.env$save.variable <- initReactive("emlal", main.env$save.variable, main.env)
+
+ .tmp <- jsonlite::read_json(paste0(path, "/", dp, ".json"))[[1]] %>%
jsonlite::unserializeJSON()
- save.variable$emlal <- setSavevar(.savevar$emlal, savevar$emlal)
-
+ # save.variable adaptations
+ # TODO remove this later
+ # - creator
+ if(isFALSE("creator" %in% names(.tmp) && isTruthy(!tmp$creator)))
+ main.env$save.variable$creator <- if(isTRUE(main.env$SETTINGS$logged))
+ main.env$SETTINGS$user
+ else
+ "public"
+ # - emlal/metafin difference
+ if (identical(names(.tmp), c("metafin", "emlal"))) {
+ .tmp <- .tmp$emlal
+ }
+ # - history
+ .tmp$history <- sapply(.tmp$history, function(h) {
+ switch(h,
+ create = "SelectDP",
+ DataFiles = "Data Files",
+ attributes = "Attributes",
+ CustomUnits = NULL,
+ CatVars = "Categorical Variables",
+ GeoCov = "Geographic Coverage",
+ TaxCov = "Taxonomic Coverage",
+ h
+ )
+ }) %>% unname()
+ # - quick mode
+ .tmp$quick <- isTRUE(.tmp$quick)
+ # Once prepared, properly set variable
+ main.env$save.variable <- setSaveVariable(.tmp, main.env$save.variable)
+
# Update paths from another file system
# * selectDP
sapply(
- names(save.variable$emlal$SelectDP),
- function(.dp.item){
- save.variable$emlal$SelectDP[[.dp.item]] <- gsub(
- pattern=".*/dataPackagesOutput/emlAssemblyLine/",
- replacement = rv$dp.location,
- save.variable$emlal$SelectDP[[.dp.item]]
+ names(main.env$save.variable$SelectDP),
+ function(.dp.item) {
+ main.env$save.variable$SelectDP[[.dp.item]] <- gsub(
+ pattern = ".*/dataPackagesOutput/emlAssemblyLine/",
+ replacement = main.env$PATHS$eal.dp,
+ main.env$save.variable$SelectDP[[.dp.item]]
)
}
)
+
# * datafiles
- if(isTruthy(save.variable$emlal$DataFiles)){
- sapply(names(save.variable$emlal$DataFiles), function(col){
- save.variable$emlal$DataFiles[,col] <- gsub(
- pattern=".*/dataPackagesOutput/emlAssemblyLine/",
- replacement = rv$dp.location,
- save.variable$emlal$DataFiles[,col]
+ if (checkTruth(main.env$save.variable$DataFiles)) {
+ sapply(names(main.env$save.variable$DataFiles), function(col) {
+ main.env$save.variable$DataFiles[, col] <- gsub(
+ pattern = ".*/dataPackagesOutput/emlAssemblyLine/",
+ replacement = main.env$PATHS$eal.dp,
+ main.env$save.variable$DataFiles[, col]
)
- if(col == "size")
- save.variable$emlal$DataFiles[,col] <- as.integer(
- save.variable$emlal$DataFiles[,col]
+ if (col == "size") {
+ main.env$save.variable$DataFiles[, col] <- as.integer(
+ main.env$save.variable$DataFiles[, col]
)
+ }
})
}
+
# * misc
- if(isTruthy(save.variable$emlal$Misc$abstract)){
- save.variable$emlal$Misc$abstract <- gsub(
+ if (checkTruth(main.env$save.variable$Misc$abstract$file)) {
+ main.env$save.variable$Misc$abstract <- gsub(
".*/dataPackagesOutput/emlAssemblyLine/",
- rv$dp.location,
- save.variable$emlal$Misc$abstract
+ main.env$PATHS$eal.dp,
+ main.env$save.variable$Misc$abstract$file
)
- save.variable$emlal$Misc$methods <- gsub(
+ main.env$save.variable$Misc$methods <- gsub(
".*/dataPackagesOutput/emlAssemblyLine/",
- rv$dp.location,
- save.variable$emlal$Misc$methods
+ main.env$PATHS$eal.dp,
+ main.env$save.variable$Misc$methods$file
)
- save.variable$emlal$Misc$additional.information <- gsub(
+ main.env$save.variable$Misc$additional.information <- gsub(
".*/dataPackagesOutput/emlAssemblyLine/",
- rv$dp.location,
- save.variable$emlal$Misc$additional.information
+ main.env$PATHS$eal.dp,
+ main.env$save.variable$Misc$additional.information$file
)
}
-
- # TODO remove this later : update history
- save.variable$emlal$history <- sapply(savevar$emlal$history, function(h) {
- switch(h,
- create = "Select Data Package",
- DataFiles = "Data Files",
- attributes = "Attributes",
- CustomUnits = NULL,
- CatVars = "Categorical Variables",
- GeoCov = "Geographic Coverage",
- TaxCov = "Taxonomic Coverage",
- h
- )
- }) %>% unname()
- save.variable$emlal$quick <- isTRUE(savevar$emlal$quick)
-
- # resume where max reached
- main.env$EAL$page <- if(save.variable$emlal$step > 1)
- -1
- else
- main.env$EAL$page + 1
- main.env$EAL$history <- save.variable$emlal$history
+
+ # resume at saved page
+ main.env$EAL$page <- main.env$save.variable$step
+ main.env$EAL$.load <- main.env$EAL$.load + 1
+ main.env$EAL$history <- main.env$save.variable$history
shinyjs::enable("dp_load")
})
-
+
# * Delete DP ----
- shinyjs::onclick("dp_delete", {
- req(input$dp_list)
-
+ observeEvent(input$dp_delete, {
+ req(isTruthy(input$dp_list))
+
# variable operation - legibility purpose
dp <- input$dp_list
-
+
# actions
showModal(
modalDialog(
title = "Delete data package?",
- paste("Are you sure to delete", dp, "?"),
+ ... = paste("Are you sure to delete", dp, "?"),
+ easyClose = FALSE,
footer = tagList(
modalButton("No"),
actionButton(
- NS(id, "delete_confirm"), "Yes",
+ NS(full.id, "delete_confirm"), "Yes",
class = "redButton"
)
) # end footer
) # end modalDialog
) # end showModal
})
-
+
# If deletion is confirmed
- shinyjs::onclick("delete_confirm", {
+ # shinyjs::onclick("delete_confirm", {
+ observeEvent(input$delete_confirm, {
# variable operation - legibility purpose
- dp <- input$dp_list
- if(grepl("\\(public\\)", dp))
- dp <- gsub(" \\(public\\)", "", dp)
- path <- paste0(rv$dp.location, dp, "_emldp")
-
+ dp <- gsub(" \\(public\\)", "", input$dp_list)
+ path <- paste0(main.env$PATHS$eal.dp, dp, "_emldp")
+
# verbose
showNotification(
- paste("Deleting:", path, "\n", sep = "")
- ) # to replace by deleting DP
-
+ paste("Deleting:", dp, sep = "")
+ )
+
# actions
unlink(path, recursive = TRUE)
- rv$dp.list <- rv$dp.list[rv$dp.list != dp]
- main.env$DP.LIST <- main.env$DP.LIST[main.env$DP.LIST$name != dp]
+ main.env$local.rv$dp.list <- main.env$local.rv$dp.list[
+ !grepl(dp, main.env$local.rv$dp.list)
+ ]
+ # main.env$DP.LIST <- main.env$DP.LIST[!grepl(dp, main.env$DP.LIST$name)]
removeModal()
})
-
- # Output ----
- return(save.variable)
})
}
diff --git a/R/eal_2_DataFiles.R b/R/eal_2_DataFiles.R
index 796b105..abd0c3f 100644
--- a/R/eal_2_DataFiles.R
+++ b/R/eal_2_DataFiles.R
@@ -1,6 +1,6 @@
#' @import shiny
#' @importFrom shinyFiles shinyFilesButton
-#'
+#'
#' @noRd
DataFilesUI <- function(id, main.env) {
return(
@@ -35,74 +35,70 @@ DataFilesUI <- function(id, main.env) {
#' @importFrom shinyFiles getVolumes shinyFileChoose parseFilePaths
#' @importFrom shinyjs onclick enable disable
#' @importFrom EMLassemblyline template_table_attributes
-#'
+#'
#' @noRd
-DataFiles <- function(id, main.env) {
- moduleServer(id, function(input, output, session){
- save.variable <- main.env$save.variable
- ns <- session$ns
-
+DataFiles <- function(id, full.id, main.env) {
+ moduleServer(id, function(input, output, session) {
+ main.env$save.variable <- main.env$save.variable
+
# Variable initialization ----
- rv <- reactiveValues(
- data.files = data.frame(stringsAsFactors = FALSE)
- )
-
- if (checkTruth(save.variable$emlal$DataFiles)) { # from create button in SelectDP
- .ind <- which(file.exists(save.variable$emlal$DataFiles$datapath))
- .col <- which(names(save.variable$emlal$DataFiles) != "metadatapath")
- rv$data.files <- save.variable$emlal$DataFiles[.ind, .col]
- }
-
- # Data file upload ----
+
+ # Data file upload ====
# * Add data files ----
observeEvent(input$add_data_files,
{
# validity checks
req(input$add_data_files)
-
+
# retrieve data files info
- loaded.files <- input$add_data_files
-
+ .loaded.files <- input$add_data_files
+
req(checkTruth(loaded.files))
-
+
# remove spaces
- loaded.files$name <- gsub(" ", "_", loaded.files$name)
-
+ .loaded.files$name <- gsub(" ", "_", .loaded.files$name)
+
# add URL, description and table name columns
- loaded.files$url <- rep("", dim(loaded.files)[1])
- loaded.files$description <- rep("", dim(loaded.files)[1])
- loaded.files$table.name <- rep("", dim(loaded.files)[1])
-
+ .loaded.files$url <- rep("", dim(.loaded.files)[1])
+ .loaded.files$description <- rep("", dim(.loaded.files)[1])
+ .loaded.files$table.name <- rep("", dim(.loaded.files)[1])
+
# bind into input
- if (isFALSE(checkTruth(rv$data.files) && all(dim(rv$data.files) > 0))) {
- rv$data.files <- loaded.files
+ if (isFALSE(
+ checkTruth(main.env$local.rv$data.files) &&
+ all(dim(main.env$local.rv$data.files) > 0)
+ )) {
+ main.env$local.rv$data.files <- .loaded.files
} else {
- sapply(loaded.files$name, function(filename){
+ sapply(.loaded.files$name, function(filename) {
if (fs::is_dir(filename)) {
showNotification(
paste(filename, "is a folder."),
type = "warning"
)
} else
- if (!filename %in% rv$data.files$name) {
- rv$data.files <- unique(rbind(
- rv$data.files,
- loaded.files[loaded.files$name == filename, ]
- ))
- }
+ if (!filename %in% main.env$local.rv$data.files$name) {
+ main.env$local.rv$data.files <- unique(rbind(
+ main.env$local.rv$data.files,
+ .loaded.files[.loaded.files$name == filename, ]
+ ))
+ }
})
}
-
- # copies on the server
+
+ # copies to the server
withProgress(
{
file.copy(
- rv$data.files$datapath,
- paste0(main.env$PATHS$eal.tmp, rv$data.files$name)
+ main.env$local.rv$data.files$datapath,
+ paste0(main.env$PATHS$eal.tmp, main.env$local.rv$data.files$name)
)
incProgress(0.8)
-
- rv$data.files$datapath <- paste0(main.env$PATHS$eal.tmp, rv$data.files$name)
+
+ main.env$local.rv$data.files$datapath <- paste0(
+ main.env$PATHS$eal.tmp,
+ main.env$local.rv$data.files$name
+ )
incProgress(0.2)
},
message = "Downloading data files"
@@ -111,26 +107,26 @@ DataFiles <- function(id, main.env) {
ignoreInit = TRUE,
label = "EAL2: add files"
)
-
+
# * Remove data files ----
observeEvent(input$remove_data_files,
{
# validity check
req(input$select_data_files)
-
+
# actions
- rv$data.files <- rv$data.files[
- !(rv$data.files$name %in% input$select_data_files),
- ]
+ main.env$local.rv$data.files <- main.env$local.rv$data.files[
+ !(main.env$local.rv$data.files$name %in% input$select_data_files),
+ ]
},
label = "EAL2: remove files"
)
-
+
# Display data files ----
# * UI ----
- observeEvent(rv$data.files, {
- df <- isolate(rv$data.files)
-
+ observeEvent(main.env$local.rv$data.files, {
+ df <- isolate(main.env$local.rv$data.files)
+
output$data_files <- renderUI({
validate(
need(
@@ -138,8 +134,9 @@ DataFiles <- function(id, main.env) {
"Select files to describe."
)
)
-
- checkboxGroupInput(NS(id, "select_data_files"),
+
+ checkboxGroupInput(
+ NS(full.id, "select_data_files"),
"Select files to delete (all files here will be kept otherwise)",
choiceNames = lapply(
df$name,
@@ -154,7 +151,7 @@ DataFiles <- function(id, main.env) {
} else {
NULL
}
-
+
# Output
collapsibleUI(
id = NS(id, .id),
@@ -199,7 +196,7 @@ DataFiles <- function(id, main.env) {
)
})
})
-
+
# * Server ----
observeEvent(names(input), {
req(
@@ -207,15 +204,15 @@ DataFiles <- function(id, main.env) {
any(grepl("dataURL", names(input))) ||
any(grepl("dataDesc", names(input)))
)
- sapply(rv$data.files$name, function(.id) {
+ sapply(main.env$local.rv$data.files$name, function(.id) {
collapsible(.id)
- ind <- match(.id, rv$data.files$name)
-
+ ind <- match(.id, main.env$local.rv$data.files$name)
+
# Data name
observeEvent(input[[paste0(ind, "-dataName")]],
{
isolate(
- rv$data.files[ind, "table.name"] <- input[[paste0(ind, "-dataName")]]
+ main.env$local.rv$data.files[ind, "table.name"] <- input[[paste0(ind, "-dataName")]]
)
},
ignoreInit = FALSE
@@ -224,7 +221,7 @@ DataFiles <- function(id, main.env) {
observeEvent(input[[paste0(ind, "-dataURL")]],
{
isolate(
- rv$data.files[ind, "url"] <- URL_Input(paste0(ind, "-dataURL"))
+ main.env$local.rv$data.files[ind, "url"] <- URL_Input(paste0(ind, "-dataURL"))
)
},
ignoreInit = FALSE
@@ -233,24 +230,24 @@ DataFiles <- function(id, main.env) {
observeEvent(input[[paste0(ind, "-dataDesc")]],
{
isolate(
- rv$data.files[ind, "description"] <- input[[paste0(ind, "-dataDesc")]]
+ main.env$local.rv$data.files[ind, "description"] <- input[[paste0(ind, "-dataDesc")]]
)
},
ignoreInit = FALSE
)
})
})
-
+
# Warnings: data size
- observeEvent(rv$data.files, {
- req(checkTruth(rv$data.files))
- files.size <- if (checkTruth(rv$data.files$size)) {
- sum(rv$data.files$size)
+ observeEvent(main.env$local.rv$data.files, {
+ req(checkTruth(main.env$local.rv$data.files))
+ files.size <- if (checkTruth(main.env$local.rv$data.files$size)) {
+ sum(main.env$local.rv$data.files$size)
} else {
0
}
files.size.max <- main.env$VALUES$thresholds$files.size.max
-
+
style <- if (files.size < 0.9 * files.size.max) {
"color: green;"
} else if (files.size >= 0.9 * files.size.max && files.size < files.size.max) {
@@ -258,8 +255,8 @@ DataFiles <- function(id, main.env) {
} else {
"color: red"
}
-
- EAL$tag.list <- tagList(
+
+ main.env$EAL$tag.list <- tagList(
"Files size:",
tags$p(
utils::object.size(files.size),
@@ -272,55 +269,48 @@ DataFiles <- function(id, main.env) {
)
)
})
-
+
# Saves ----
observe({
- main.env$EAL$completed <- checkTruth(rv$data.files) &&
- all(dim(rv$data.files) > 0)
+ main.env$EAL$completed <- checkTruth(main.env$local.rv$data.files) &&
+ all(dim(main.env$local.rv$data.files) > 0)
})
-
- # observeEvent(NSB$SAVE,
+
shinyjs::onclick(
"fill-wizard-save",
asis = TRUE,
add = TRUE,
{
req(main.env$EAL$current == "Data Files")
- req(isTruthy(rv$data.files$name))
-
- save.variable <- saveReactive(
- save.variable = savevar,
- rv = list(DataFiles = rv)
- )
- },
- label = "Save_DataFiles",
- ignoreInit = TRUE
+ req(isTruthy(main.env$local.rv$data.files$name))
+
+ saveReactive(main.env)
+ # save.variable = main.env$save.variable,
+ # content = list(DataFiles = main.env$local.rv)
+ # )
+ }
)
-
+
# Process files ----
- observeEvent(EAL$.next,
- {
- req(main.env$EAL$current == "Data Files")
- # Save
- save.variable <- saveReactive(
- save.variable,
- rv = list(DataFiles = rv)
- )
-
- # EMLAL templating function
- try(
- EMLassemblyline::template_table_attributes(
- path = save.variable$emlal$SelectDP$dp.metadata.path,
- data.path = save.variable$emlal$SelectDP$dp.data.path,
- data.table = save.variable$emlal$DataFiles$name
- )
+ observeEvent(main.env$EAL$.next, {
+ req(main.env$EAL$current == "Data Files")
+ # Save
+ saveReactive(main.env)
+ # save.variable = main.env$save.variable,
+ # content = list(DataFiles = main.env$local.rv)
+ # )
+
+ # EMLAL templating function
+ try(
+ EMLassemblyline::template_table_attributes(
+ path = isolate(main.env$save.variable$SelectDP$dp.metadata.path),
+ data.path = isolate(main.env$save.variable$SelectDP$dp.data.path),
+ data.table = isolate(main.env$save.variable$DataFiles$name)
)
- },
- priority = 1,
- ignoreInit = TRUE
+ )
+ },
+ priority = 1,
+ ignoreInit = TRUE
)
-
- # Output ----
- return(save.variable)
})
}
diff --git a/R/eal_3_Attributes.R b/R/eal_3_Attributes.R
index 3882e3d..8d781c1 100644
--- a/R/eal_3_Attributes.R
+++ b/R/eal_3_Attributes.R
@@ -3,11 +3,11 @@
#' @description UI part of the Attributes module. Fill in the attributes of the data package
#'
#' @import shiny
-#'
+#'
#' @noRd
AttributesUI <- function(id, main.env) {
ns <- NS(id)
-
+
return(
fluidPage(
tagList(
@@ -44,8 +44,7 @@ AttributesUI <- function(id, main.env) {
fluidRow(
column(
12,
- uiOutput(NS(id, "edit_attributes")) %>%
- shinycssloaders::withSpinner(color = "#599cd4")
+ uiOutput(NS(id, "edit_attributes"))
)
),
# Custom Units
@@ -62,204 +61,226 @@ AttributesUI <- function(id, main.env) {
#' @importFrom shinyjs hide show enable disable onclick
#' @importFrom EMLassemblyline template_categorical_variables template_geographic_coverage
#' @importFrom shinyBS bsCollapse bsCollapsePanel updateCollapse
-#'
+#'
#' @noRd
-Attributes <- function(id, main.env) {
- moduleServer(id, function(input, output, session){
- save.variable <- main.env$save.variable
- ns <- session$ns
-
- if (main.env$DEV || isTRUE(save.variable$emlal$quick)) {
+Attributes <- function(id, full.id, main.env) {
+ moduleServer(id, function(input, output, session) {
+ main.env$save.variable <- isolate(main.env$save.variable)
+
+ if (isTRUE(main.env$dev) || isTRUE(main.env$save.variable$quick)) {
.fill <- function(rv = rv) {
- lapply(seq(rv$tables), function(ind) {
- .table <- rv$tables[[ind]]
+ lapply(seq(main.env$local.rv$tables), function(ind) {
+ .table <- main.env$local.rv$tables[[ind]]
sapply(colnames(.table), function(col) {
# Set values
if (col == "attributeDefinition") {
- rv$tables[[ind]][[col]] <- paste("Description for", rv$tables[[ind]][["attributeName"]])
+ main.env$local.rv$tables[[ind]][[col]] <- paste("Description for", main.env$local.rv$tables[[ind]][["attributeName"]])
}
if (col %in% c("missingValueCodeExplanation", "missingValueCode")) {
- rv$tables[[ind]][[col]] <- rep("LoremIpsum", dim(.table)[1])
+ main.env$local.rv$tables[[ind]][[col]] <- rep("LoremIpsum", dim(.table)[1])
}
if (col == "dateTimeFormatString") {
- .dat.row <- which(rv$tables[[ind]]$class == "Date")
- rv$tables[[ind]][[col]] <- rep("", dim(.table)[1])
- if(isTruthy(.dat.row))
- rv$tables[[ind]][.dat.row, col] <- rep(main.env$FORMATS$dates[3], length(.dat.row))
+ .dat.row <- which(main.env$local.rv$tables[[ind]]$class == "Date")
+ main.env$local.rv$tables[[ind]][[col]] <- rep("", dim(.table)[1])
+ if (isTruthy(.dat.row)) {
+ main.env$local.rv$tables[[ind]][.dat.row, col] <- rep(main.env$FORMATS$dates[3], length(.dat.row))
+ }
}
if (col == "unit") {
- .uni.row <- which(rv$tables[[ind]]$class == "numeric")
- rv$tables[[ind]][[col]] <- rep("", dim(.table)[1])
- if(isTruthy(.uni.row))
- rv$tables[[ind]][.uni.row, col] <- rep(main.env$FORMATS$dates[2], length(.uni.row))
+ .uni.row <- which(main.env$local.rv$tables[[ind]]$class == "numeric")
+ main.env$local.rv$tables[[ind]][[col]] <- rep("", dim(.table)[1])
+ if (isTruthy(.uni.row)) {
+ main.env$local.rv$tables[[ind]][.uni.row, col] <- rep(main.env$FORMATS$dates[2], length(.uni.row))
+ }
}
-
+
# Update values
- if (ind == rv$current.file) {
- sapply(1:dim(rv$tables[[ind]])[1], function(item) {
+ if (ind == main.env$local.rv$current.file) {
+ sapply(1:dim(main.env$local.rv$tables[[ind]])[1], function(item) {
inputId <- paste(ind, item, col, sep = "-")
if (inputId %in% names(input)) {
if (col %in% c("unit", "dateTimeFormatString")) {
- updateSelectInput(session, inputId, selected = rv$tables[[ind]][item, col])
+ updateSelectInput(session, inputId, selected = main.env$local.rv$tables[[ind]][item, col])
}
if (col %in% c("attributeDefinition", "missingValueCode", "missingValueCodeExplanation")) {
- updateTextAreaInput(session, inputId, value = rv$tables[[ind]][item, col])
+ updateTextAreaInput(session, inputId, value = main.env$local.rv$tables[[ind]][item, col])
}
}
})
}
}) # end of sapply
-
+
# Update current table
- if (ind == rv$current.file) {
- rv$current.table <- rv$tables[[ind]]
+ if (ind == main.env$local.rv$current.file) {
+ main.env$local.rv$current.table <- main.env$local.rv$tables[[ind]]
}
}) # end of lapply
return(rv)
} # end of .fill
}
-
+
# variable initialization ----
- rv <- reactiveValues(
- data.filepath = save.variable$emlal$DataFiles$datapath,
- filepath = save.variable$emlal$DataFiles$metadatapath,
- filenames = basename(save.variable$emlal$DataFiles$metadatapath),
- current.file = 1,
- tables = NULL,
- current.table = NULL,
- current.preview = NULL,
- cu.table = data.frame(stringsAsFactors = FALSE),
- cu.values = rep(NA, 5),
- modal.on = FALSE,
- unit.id = character(),
- units.list = character(),
- annotations = reactiveValues(
- values = data.frame(stringsAsFactors = FALSE),
- count = 0
- )
- )
- rv$tables <- lapply(
- rv$filepath, readDataTable,
- data.table = FALSE, stringsAsFactors = FALSE
- )
- rv$current.table <- rv$tables[[rv$current.file]]
- rv$cu.table <- readDataTable(
- dir(
- save.variable$emlal$SelectDP$dp.metadata.path,
- pattern = "ustom",
- full.names = TRUE
- ),
- stringsAsFactors = FALSE,
+ # rv <- reactiveValues(
+ # current.file = 0,
+ # tables = NULL,
+ # current.table = NULL,
+ # current.preview = NULL,
+ # cu.table = data.frame(stringsAsFactors = FALSE),
+ # cu.values = rep(NA, 5),
+ # modal.on = FALSE,
+ # unit.id = character(),
+ # units.list = isolate(main.env$FORMATS$units),
+ # annotations = reactiveValues(
+ # values = data.frame(stringsAsFactors = FALSE),
+ # count = 0
+ # )
+ # )
+
+ # Set a bunch of local variables when loading this page
+ main.env$pageLoad(3, {
+ # Path to data files
+ main.env$local.rv$data.filepath <- main.env$save.variable$DataFiles$datapath
+ main.env$local.rv$current.file <- as.numeric(checkTruth(main.env$local.rv$data.filepath))
+
+ # Path to metadata templates
+ main.env$local.rv$filepath <- main.env$save.variable$DataFiles$metadatapath
+ if (checkTruth(main.env$local.rv$filepath)) {
+ main.env$local.rv$filenames <- basename(main.env$local.rv$filepath)
+ main.env$local.rv$tables <- lapply(
+ main.env$local.rv$filepath, readDataTable,
+ data.table = FALSE, stringsAsFactors = FALSE
+ )
+ main.env$local.rv$current.table <- main.env$local.rv$tables[[main.env$local.rv$current.file]]
+ }
+
+ # Path to metadata directory
+ if (checkTruth(main.env$save.variable$SelectDP$dp.metadata.path)) {
+ main.env$local.rv$cu.table <- readDataTable(
+ dir(
+ isolate(main.env$save.variable$SelectDP$dp.metadata.path),
+ pattern = "ustom",
+ full.names = TRUE
+ ),
+ stringsAsFactors = FALSE
+ )
+ }
+ })
+
+ # if (checkTruth(main.env$save.variable$Attributes$annotations)) {
+ # rv$annotations$values <- isolate(main.env$save.variable$Attributes$annotations)
+ # rv$annotations$count <- nrow(rv$annotations$values)
+ # }
+ # else {
+ # rv$annotations$values <- data.frame(
+ # id = character(),
+ # element = character(),
+ # context = character(),
+ # subject = character(),
+ # predicate_label = character(),
+ # predicate_uri = character(),
+ # object_label = character(),
+ # object_uri = character(),
+ # stringsAsFactors = FALSE
+ # )
+ # }
+
+ observeEvent(main.env$save.variable$quick,
+ {
+ # Selected quick selection and not gone further
+ if (isTRUE(main.env$save.variable$quick) &&
+ length(main.env$save.variable$EAL$history) < 4) {
+ main.env$local.rv <- .fill(main.env$local.rv)
+ }
+ },
+ once = TRUE
)
- rv$units.list <- main.env$FORMATS$units
- if (checkTruth(save.variable$emlal$Attributes$annotations)) {
- rv$annotations$values <- save.variable$emlal$Attributes$annotations
- rv$annotations$count <- nrow(rv$annotations$values)
- }
- else {
- rv$annotations$values <- data.frame(
- id = character(),
- element = character(),
- context = character(),
- subject = character(),
- predicate_label = character(),
- predicate_uri = character(),
- object_label = character(),
- object_uri = character(),
- stringsAsFactors = FALSE
- )
- }
-
- if (isTRUE(save.variable$emlal$quick)) {
- rv <- .fill(rv)
- }
-
+
+ # Update unit list with customs
observe(
{
- . <- rv$current.table # trigger
-
+ .tab <- isolate(main.env$local.rv$current.table) # trigger
+ req(.tab)
.tmp <- unique(c(
- unlist(lapply(seq_along(rv$tables), function(t) {
- .tab <- if (t == rv$current.file) {
- rv$current.table
+ unlist(lapply(seq_along(main.env$local.rv$tables), function(t) {
+ if (t == main.env$local.rv$current.file) {
+ return(.tab$unit)
} else {
- rv$tables[[t]]
+ return(main.env$local.rv$tables[[t]]$unit)
}
- .tab$unit
})),
main.env$FORMATS$units
))
- rv$units.list <- .tmp[.tmp != ""]
+ main.env$local.rv$units.list <- .tmp[.tmp != ""]
},
label = "EAL3: unit list"
)
-
+
# Reactive triggers
curt <- makeReactiveTrigger()
-
+
# List of observers
obs <- reactiveValues()
-
+
# Navigation buttons ----
onclick("file_prev", {
- req(rv$current.file > 1)
+ req(main.env$local.rv$current.file > 1)
# Save
- if (!is.null(rv$current.table)) {
- rv$tables[[rv$current.file]] <- rv$current.table
+ if (!is.null(main.env$local.rv$current.table)) {
+ main.env$local.rv$tables[[main.env$local.rv$current.file]] <- main.env$local.rv$current.table
}
# Change file
- rv$current.file <- rv$current.file - 1
+ main.env$local.rv$current.file <- main.env$local.rv$current.file - 1
})
-
+
onclick("file_next", {
- req(rv$current.file < length(rv$filenames))
+ req(main.env$local.rv$current.file < length(main.env$local.rv$filenames))
# Save
- if (!is.null(rv$current.table)) {
- rv$tables[[rv$current.file]] <- rv$current.table
+ if (!is.null(main.env$local.rv$current.table)) {
+ main.env$local.rv$tables[[main.env$local.rv$current.file]] <- main.env$local.rv$current.table
}
# Change file
- rv$current.file <- rv$current.file + 1
+ main.env$local.rv$current.file <- main.env$local.rv$current.file + 1
})
-
+
# update table
- observeEvent(rv$current.file,
+ observeEvent(main.env$local.rv$current.file,
{
- req(rv$current.file > 0)
- rv$current.table <- rv$tables[[rv$current.file]]
- rv$current.table[is.na(rv$current.table)] <- ""
- rv$current.preview <- readDataTable(
- rv$data.filepath[rv$current.file],
+ req(main.env$local.rv$current.file > 0)
+ main.env$local.rv$current.table <- main.env$local.rv$tables[[main.env$local.rv$current.file]]
+ main.env$local.rv$current.table[is.na(main.env$local.rv$current.table)] <- ""
+ main.env$local.rv$current.preview <- readDataTable(
+ main.env$local.rv$data.filepath[main.env$local.rv$current.file],
stringsAsFactors = FALSE,
nrows = 5
)
},
priority = 1
)
-
+
# display
output$current_file <- renderUI(
tags$div(
- rv$filenames[rv$current.file],
+ main.env$local.rv$filenames[main.env$local.rv$current.file],
class = "ellipsis",
style = paste0(
"display: inline-block;
- font-size:14pt;
- text-align:center;
- width:100%;
- background: linear-gradient(90deg, #3c8dbc ",
- round(100 * rv$current.file / length(rv$filenames)),
+ font-size:14pt;
+ text-align:center;
+ width:100%;
+ background: linear-gradient(90deg, #3c8dbc ",
+ round(100 * main.env$local.rv$current.file / length(main.env$local.rv$filenames)),
"%, white ",
- round(100 * rv$current.file / length(rv$filenames)),
+ round(100 * main.env$local.rv$current.file / length(main.env$local.rv$filenames)),
"%);"
)
)
)
-
+
# * UI ----
- observeEvent(rv$current.file, {
- req(checkTruth(rv$current.table))
- .current.table <- isolate(rv$current.table)
-
+ observeEvent(main.env$local.rv$current.file, {
+ req(checkTruth(main.env$local.rv$current.table))
+ .current.table <- main.env$local.rv$current.table
+
output$edit_attributes <- renderUI({
# validity check
validate(
@@ -269,7 +290,7 @@ Attributes <- function(id, main.env) {
"No valid attributes table."
)
)
-
+
ui <- do.call(
bsCollapse,
args = c(
@@ -279,7 +300,7 @@ Attributes <- function(id, main.env) {
function(row.index, fields) {
# prepare variables
attribute.row <- .current.table[row.index, ]
-
+
return(
bsCollapsePanel(
title = attribute.row[fields[1]],
@@ -291,11 +312,11 @@ Attributes <- function(id, main.env) {
# prepare var
saved.value <- .current.table[row.index, colname]
inputId <- paste(
- isolate(rv$current.file),
+ isolate(main.env$local.rv$current.file),
row.index,
sep = "-"
)
-
+
# GUI
attributeInputUI(
NS(id, inputId),
@@ -312,8 +333,8 @@ Attributes <- function(id, main.env) {
h4("Preview:"),
tableOutput(
NS(id, paste0(
- "preview-",
- colnames(rv$current.preview)[row.index]
+ "preview-",
+ colnames(main.env$local.rv$current.preview)[row.index]
))
),
tags$hr(),
@@ -341,27 +362,27 @@ Attributes <- function(id, main.env) {
return(ui)
})
}) # end of observeEvent
-
+
# * Server ----
- observeEvent(rv$current.file, {
- req(checkTruth(rv$current.table))
-
+ observeEvent(main.env$local.rv$current.file, {
+ req(checkTruth(main.env$local.rv$current.table))
+
sapply(
- seq(dim(rv$current.table)[1]),
- fields = colnames(rv$current.table)[-1], # not Attribute Name
+ seq(dim(main.env$local.rv$current.table)[1]),
+ fields = colnames(main.env$local.rv$current.table)[-1], # not Attribute Name
function(row.index, fields) {
-
+
# TODO Update style: to correct
# updateCollapse(
# session = session,
# NS(id, "collapse"),
# style = filled
# )
-
+
# Preview ====
- preview.column <- colnames(rv$current.preview)[row.index]
- output[[paste0("preview-", preview.column)]] <- renderTable(rv$current.preview[[preview.column]])
-
+ preview.column <- colnames(main.env$local.rv$current.preview)[row.index]
+ output[[paste0("preview-", preview.column)]] <- renderTable(main.env$local.rv$current.preview[[preview.column]])
+
# Annotate ====
# annotateId <- paste(
# "annotate",
@@ -369,20 +390,20 @@ Attributes <- function(id, main.env) {
# row.index,
# sep = "-"
# )
- #
+ #
# .tmp <- callModule(
# annotate, annotateId,
# save.variable, main.env, rv, row.index
# )
-
+
# Input ====
lapply(fields, function(colname) {
inputId <- paste(
- isolate(rv$current.file),
+ isolate(main.env$local.rv$current.file),
row.index,
sep = "-"
)
-
+
obs <- attributeInput(
inputId,
rv,
@@ -395,41 +416,43 @@ Attributes <- function(id, main.env) {
} # end of *in situ* function
) # end of sapply : row.index
}) # end of observeEvent
-
+
# Custom units ----
observe({
curt$depend()
- .current.table <- isolate(rv$current.table)
- modal.on <- isolate(rv$modal.on)
+ .current.table <- main.env$local.rv$current.table
+ modal.on <- isolate(main.env$local.rv$modal.on)
+
+ req(isTruthy(.current.table))
req(any(.current.table$unit == "custom"))
-
- rv$unit.id <- c(
- rv$current.file,
+
+ main.env$local.rv$unit.id <- c(
+ main.env$local.rv$current.file,
which(.current.table$unit == "custom"),
"unit"
)
-
- row <- rv$unit.id[2]
+
+ row <- main.env$local.rv$unit.id[2]
class <- .current.table[row, "class"]
-
+
if (class == "numeric" &&
- modal.on == FALSE) {
- rv$cu.values <- rv$cu.table %>%
+ modal.on == FALSE) {
+ main.env$local.rv$cu.values <- main.env$local.rv$cu.table %>%
dplyr::filter(grepl(class, id))
- if (any(dim(rv$cu.values) == 0)) {
- rv$cu.values <- rep(NA, 5)
+ if (any(dim(main.env$local.rv$cu.values) == 0)) {
+ main.env$local.rv$cu.values <- rep(NA, 5)
}
-
- showModal(CU_Modal(rv$cu.values, cu.table = rv$cu.table))
-
- rv$modal.on <- TRUE
-
+
+ showModal(CU_Modal(main.env$local.rv$cu.values, cu.table = main.env$local.rv$cu.table))
+
+ main.env$local.rv$modal.on <- TRUE
+
isolate({
- rv$current.table[row, "unit"] <- ""
+ main.env$local.rv$current.table[row, "unit"] <- ""
})
}
})
-
+
CU_Modal <- function(values = rep(NA, 5), cu.table = NULL) {
modalDialog(
title = "Custom Unit",
@@ -481,55 +504,55 @@ Attributes <- function(id, main.env) {
)
)
}
-
+
# * CU server ----
# Cancel
onclick("modal_cancel", {
- req(isTRUE(rv$modal.on))
-
+ req(isTRUE(main.env$local.rv$modal.on))
+
# Close modal
- rv$modal.on <- FALSE
+ main.env$local.rv$modal.on <- FALSE
removeModal()
-
+
isolate({
updateSelectInput(
session,
- paste(rv$unit.id, collapse = "-"),
+ paste(main.env$local.rv$unit.id, collapse = "-"),
selected = main.env$FORMATS$units[2]
)
})
- rv$unit.id <- character() # reset to default
+ main.env$local.rv$unit.id <- character() # reset to default
})
-
+
# Submit button en/disable
observe({
- req(isTRUE(rv$modal.on))
-
+ req(isTRUE(main.env$local.rv$modal.on))
+
# type a new one
- if (!input$modal_id %in% rv$cu.table$id &&
- input$modal_id != "custom" &&
- isTruthy(input$modal_id) &&
- isTruthy(input$modal_unitType) &&
- isTruthy(input$modal_parentSI) &&
- isTruthy(input$modal_multiplier) &&
- isTruthy(input$modal_description)) {
+ if (!input$modal_id %in% main.env$local.rv$cu.table$id &&
+ input$modal_id != "custom" &&
+ isTruthy(input$modal_id) &&
+ isTruthy(input$modal_unitType) &&
+ isTruthy(input$modal_parentSI) &&
+ isTruthy(input$modal_multiplier) &&
+ isTruthy(input$modal_description)) {
shinyjs::enable("modal_submit")
} else {
shinyjs::disable("modal_submit")
}
})
-
+
# Submit
observeEvent(input$modal_submit,
{
- req(isTRUE(rv$modal.on))
-
+ req(isTRUE(main.env$local.rv$modal.on))
+
# Close modal
removeModal()
- rv$modal.on <- FALSE
-
+ main.env$local.rv$modal.on <- FALSE
+
isolate({
- rv$cu.values <- c(
+ main.env$local.rv$cu.values <- c(
input$modal_id,
input$modal_unitType,
input$modal_parentSI,
@@ -537,58 +560,58 @@ Attributes <- function(id, main.env) {
input$modal_description
)
})
-
+
# Update CU values
- if (rv$cu.values[1] %in% rv$cu.table$id) {
- rv$cu.table <- rv$cu.table %>%
- dplyr::filter(id = rv$cu.values[1]) %>%
- base::replace(values = rv$cu.values)
+ if (main.env$local.rv$cu.values[1] %in% main.env$local.rv$cu.table$id) {
+ main.env$local.rv$cu.table <- main.env$local.rv$cu.table %>%
+ dplyr::filter(id = main.env$local.rv$cu.values[1]) %>%
+ base::replace(values = main.env$local.rv$cu.values)
} # Add CU values
else {
- names(rv$cu.values) <- colnames(rv$cu.table)
- rv$cu.table[dim(rv$cu.table)[1] + 1,] <- rv$cu.values
+ names(main.env$local.rv$cu.values) <- colnames(main.env$local.rv$cu.table)
+ main.env$local.rv$cu.table[dim(main.env$local.rv$cu.table)[1] + 1, ] <- main.env$local.rv$cu.values
}
# update input UI
- rv$units.list <- unique(c(
- rv$cu.values["id"],
- rv$units.list
+ main.env$local.rv$units.list <- unique(c(
+ main.env$local.rv$cu.values["id"],
+ main.env$local.rv$units.list
))
isolate({
updateSelectInput(
session,
- paste(rv$unit.id, collapse = "-"),
- choices = rv$units.list,
- selected = rv$cu.values["id"]
+ paste(main.env$local.rv$unit.id, collapse = "-"),
+ choices = main.env$local.rv$units.list,
+ selected = main.env$local.rv$cu.values["id"]
)
})
-
- row <- rv$unit.id[2]
- rv$current.table[row, "unit"] <- rv$cu.values["id"]
+
+ row <- main.env$local.rv$unit.id[2]
+ main.env$local.rv$current.table[row, "unit"] <- main.env$local.rv$cu.values["id"]
},
priority = 1
)
-
+
output$CUUI <- renderTable({
validate(
- need(isTruthy(unlist(rv$cu.table)), "No custom units registered")
+ need(isTruthy(unlist(main.env$local.rv$cu.table)), "No custom units registered")
)
- return(rv$cu.table)
+ main.env$local.rv$cu.table
})
-
+
# Saves ----
# observeEvent(rv$tables, {
observe(
{
main.env$EAL$completed <- FALSE
req(
- length(rv$tables) != 0 &&
- !any(sapply(rv$tables, identical, y = data.frame()))
+ length(main.env$local.rv$tables) != 0 &&
+ !any(sapply(main.env$local.rv$tables, identical, y = data.frame()))
)
-
+
main.env$EAL$completed <- all(
unlist(
lapply(
- rv$tables,
+ main.env$local.rv$tables,
function(table) {
isTruthy(table) &&
all(sapply(table$attributeName, isTruthy)) &&
@@ -603,7 +626,7 @@ Attributes <- function(id, main.env) {
},
priority = -1
)
-
+
# observeEvent(NSB$SAVE,
shinyjs::onclick(
"fill-wizard-save",
@@ -611,81 +634,79 @@ Attributes <- function(id, main.env) {
add = TRUE,
{
req(utils::tail(main.env$EAL$history, 1) == "Attributes")
-
- save.variable <- saveReactive(
- save.variable = savevar,
- rv = list(Attributes = rv)
- )
- },
- label = "Save_Attributes",
- ignoreInit = TRUE
+
+ saveReactive(main.env)
+ # save.variable = main.env$save.variable,
+ # rv = list(Attributes = rv)
+ # )
+ }
)
-
+
# en/disable buttons
- observeEvent(rv$current.file, {
+ observeEvent(main.env$local.rv$current.file, {
req(
isTruthy(names(input)) &&
- isTruthy(names(rv$current.file))
+ isTruthy(names(main.env$local.rv$current.file))
)
-
- if (rv$current.file == 1) {
+
+ if (main.env$local.rv$current.file == 1) {
shinyjs::disable("file_prev")
} else {
shinyjs::enable("file_prev")
}
- if (rv$current.file == length(rv$filenames)) {
+ if (main.env$local.rv$current.file == length(main.env$local.rv$filenames)) {
shinyjs::disable("file_next")
} else {
shinyjs::enable("file_next")
}
})
-
+
# Process data ----
- observeEvent(EAL$.next,
+ observeEvent(main.env$EAL$.next,
{
req(main.env$EAL$current == "Attributes")
-
+
withProgress({
setProgress(0.5, "Saving metadata")
-
- save.variable <- saveReactive(
- save.variable = savevar,
- rv = list(Attributes = rv)
- )
-
+
+ saveReactive(main.env)
+ # save.variable = main.env$save.variable,
+ # rv = list(Attributes = rv)
+ # )
+
# for each attribute data frame
setProgress(0.8, "Resolving catvar templates")
.do.template.catvars <- sapply(
- seq_along(rv$filenames),
+ seq_along(main.env$local.rv$filenames),
function(cur_ind) {
-
+
# check for direction: CustomUnits or CatVars
- return(isTRUE("categorical" %in% rv$tables[[cur_ind]][, "class"]))
+ return(isTRUE("categorical" %in% main.env$local.rv$tables[[cur_ind]][, "class"]))
}
) %>%
unlist() %>%
any()
-
+
# EMLAL: template new fields if needed
if (isTRUE(.do.template.catvars)) {
try(
EMLassemblyline::template_categorical_variables(
- path = save.variable$emlal$SelectDP$dp.metadata.path,
- data.path = save.variable$emlal$SelectDP$dp.data.path
+ path = main.env$save.variable$SelectDP$dp.metadata.path,
+ data.path = main.env$save.variable$SelectDP$dp.data.path
)
)
}
-
+
setProgress(0.9, "Templating geographic coverage")
try(
EMLassemblyline::template_geographic_coverage(
- path = save.variable$emlal$SelectDP$dp.metadata.path,
- data.path = save.variable$emlal$SelectDP$dp.data.path,
+ path = main.env$save.variable$SelectDP$dp.metadata.path,
+ data.path = main.env$save.variable$SelectDP$dp.data.path,
empty = TRUE,
write.file = TRUE
)
)
-
+
if (isFALSE(.do.template.catvars)) {
isolate(main.env$EAL$page <- main.env$EAL$page + 1)
}
@@ -695,8 +716,5 @@ Attributes <- function(id, main.env) {
priority = 1,
ignoreInit = TRUE
)
-
- # Output ----
- return(save.variable)
})
}
diff --git a/R/eal_3_attributeInput.R b/R/eal_3_attributeInput.R
index b1f0ea4..92bc474 100644
--- a/R/eal_3_attributeInput.R
+++ b/R/eal_3_attributeInput.R
@@ -1,7 +1,7 @@
#' @import shiny
attributeInputUI <- function(id, colname, value, formats, rv) {
ns <- NS(id)
-
+
ui <- switch(colname,
attributeDefinition = textAreaInput(
NS(id, colname),
@@ -52,21 +52,20 @@ attributeInputUI <- function(id, colname, value, formats, rv) {
),
NULL
) # end of switch
-
+
return(ui)
}
#' @import shiny
#' @importFrom shinyjs show hide
-attributeInput <- function(id, rv, row.index, colname, obs, curt){
+attributeInput <- function(id, rv, row.index, colname, obs, curt) {
moduleServer(id, function(input, output, session) {
-
obs[[NS(id, colname)]] <- observeEvent(input[[colname]],
{
req(input[[colname]])
-
+
.val <- input[[colname]]
-
+
# Class ====
if (colname == "class") {
# Date
@@ -78,7 +77,7 @@ attributeInput <- function(id, rv, row.index, colname, obs, curt){
isolate(rv$current.table[row.index, "dateTimeFormatString"] <- "")
shinyjs::hide(date.id)
}
-
+
# Unit
unit.id <- "unit"
if (input[[colname]] == "numeric") {
@@ -93,7 +92,7 @@ attributeInput <- function(id, rv, row.index, colname, obs, curt){
if (colname == "missingValueCode") { # input: missing Value code
if (grepl(".+ +.*", input[[colname]])) {
.val <- strsplit(gsub("^ +", "", .val), split = " ")[[1]][1]
-
+
updateTextInput(
session,
colname,
@@ -112,10 +111,10 @@ attributeInput <- function(id, rv, row.index, colname, obs, curt){
if (grepl("unit", NS(id, colname))) {
# Trigger CU
if (input[[colname]] == "custom" &&
- isFALSE(rv$modal.on)) {
+ isFALSE(rv$modal.on)) {
curt$trigger()
}
-
+
if (isFALSE(input[[colname]] %in% rv$units.list)) {
.cu <- rv$current.table[row.index, colname]
if (.cu %in% rv$cu.table$id) {
@@ -124,22 +123,23 @@ attributeInput <- function(id, rv, row.index, colname, obs, curt){
}
}
}
-
+
# Set values ====
- if(
- (colname == "unit" &&
- rv$current.table[row.index, "class"] != "numeric") ||
- (colname == "dateTimeFormatString" &&
- rv$current.table[row.index, "class"] != "Date")
- )
+ if (
+ (colname == "unit" &&
+ rv$current.table[row.index, "class"] != "numeric") ||
+ (colname == "dateTimeFormatString" &&
+ rv$current.table[row.index, "class"] != "Date")
+ ) {
.val <- ""
+ }
rv$current.table[row.index, colname] <- .val
rv$tables[[rv$current.file]] <- rv$current.table
},
label = NS(id, colname)
)
-
+
# Output ----
return(obs)
})
-}
\ No newline at end of file
+}
diff --git a/R/eal_4_CatVars.R b/R/eal_4_CatVars.R
index ee523fd..a60f4cf 100644
--- a/R/eal_4_CatVars.R
+++ b/R/eal_4_CatVars.R
@@ -1,7 +1,7 @@
#' @import shiny
CatVarsUI <- function(id, main.env) {
ns <- NS(id)
-
+
return(
fluidPage(
fluidRow(
@@ -43,144 +43,149 @@ CatVarsUI <- function(id, main.env) {
#' @importFrom dplyr %>% filter select mutate
#' @importFrom shinyBS bsCollapse bsCollapsePanel
#' @importFrom shinyjs onclick
-#'
+#'
#' @noRd
-CatVars <- function(id, main.env) {
- moduleServer(id, function(input, output, session){
- save.variable <- main.env$save.variable
-
+CatVars <- function(id, full.id, main.env) {
+ moduleServer(id, function(input, output, session) {
+ main.env$save.variable <- main.env$save.variable
+
# variables initialization ----
- rv <- reactiveValues(
- catvar.files = list.files(
- save.variable$emlal$SelectDP$dp.metadata.path,
+ # rv <- reactiveValues(
+ # current.index = 0
+ # )
+
+ main.env$pageLoad(4, {
+ . <- isolate(main.env$save.variable$SelectDP$dp.metadata.path)
+ req(.)
+ main.env$local.rv$catvar.files <- list.files(
+ .,
pattern = "catvar",
full.names = TRUE
- ),
- current.index = 1
- )
-
- # update current file
- observeEvent(rv$current.index,
- {
- rv$current.file <- basename(rv$catvar.files[rv$current.index])
- },
- priority = 1,
- ignoreInit = FALSE
- )
-
+ )
+ # update current file
+ req(main.env$local.rv$catvar.files)
+ main.env$local.rv$current.index <- as.numeric(checkTruth(main.env$local.rv$catvar.files))
+ main.env$local.rv$current.file <- basename(main.env$local.rv$catvar.files[main.env$local.rv$current.index])
+ })
+
# Set each reactivevalues per file
- sapply(rv$catvar.files, function(file.path) {
- file.name <- basename(file.path)
- rv[[file.name]] <- reactiveValues()
-
- # * Init data frame ====
- rv[[file.name]]$CatVars <- fread(
- file.path,
- data.table = FALSE, stringsAsFactors = FALSE,
- na.strings = "NA"
- ) %>%
- dplyr::mutate(
- definition = if (definition == "NA" || is.na(definition)) {
- paste("Value:", code, "for attribute:", attributeName)
- } else {
- definition
+ observeEvent(main.env$local.rv$catvar.files, {
+ req(isTruthy(main.env$local.rv$catvar.files))
+
+ sapply(main.env$local.rv$catvar.files, function(file.path) {
+ file.name <- basename(file.path)
+ main.env$local.main.env$local.rv[[file.name]] <- reactiveValues()
+
+ # * Init data frame ====
+ main.env$local.main.env$local.rv[[file.name]]$CatVars <- fread(
+ file.path,
+ data.table = FALSE, stringsAsFactors = FALSE,
+ na.strings = "NA"
+ ) %>%
+ dplyr::mutate(
+ definition = if (definition == "NA" || is.na(definition)) {
+ paste("Value:", code, "for attribute:", attributeName)
+ } else {
+ definition
+ }
+ )
+
+ # * Write UI ====
+ .content <- lapply(
+ unique(main.env$local.main.env$local.rv[[file.name]]$CatVars$attributeName),
+ function(attribute) {
+ # get codes aka values for `attribute` in catvar_*.txt
+ codes <- main.env$local.main.env$local.rv[[file.name]]$CatVars %>%
+ dplyr::filter(attributeName == attribute) %>%
+ dplyr::select(code)
+
+ bsCollapsePanel(
+ title = attribute,
+ # value = attribute,
+ ... = tagList(
+ lapply(unlist(codes), function(cod) {
+ if (is.na(cod)) {
+ cod <- "NA"
+ }
+
+ input.id <- paste(
+ attribute,
+ cod %>%
+ gsub("[ [:punct:]]", "", .),
+ sep = "-"
+ )
+
+ textAreaInput(
+ NS(id, input.id),
+ cod,
+ value = main.env$local.rv[[file.name]]$CatVars %>%
+ dplyr::filter(attributeName == attribute, code == cod) %>%
+ dplyr::select(definition) %>%
+ unique()
+ )
+ })
+ ) # end of "tagapply" -- text areas
+ ) # end of bsCollapsePanel
}
- )
-
- # * Write UI ====
- .content <- lapply(
- unique(rv[[file.name]]$CatVars$attributeName),
- function(attribute) {
- # get codes aka values for `attribute` in catvar_*.txt
- codes <- rv[[file.name]]$CatVars %>%
- dplyr::filter(attributeName == attribute) %>%
- dplyr::select(code)
-
- bsCollapsePanel(
- title = attribute,
- # value = attribute,
- ... = tagList(
- lapply(unlist(codes), function(cod) {
- if(is.na(cod))
- cod <- "NA"
-
- input.id <- paste(
- attribute,
- cod %>%
- gsub("[ [:punct:]]", "", .),
- sep = "-"
- )
-
- textAreaInput(
- NS(id, input.id),
- cod,
- value = rv[[file.name]]$CatVars %>%
- dplyr::filter(attributeName == attribute, code == cod) %>%
- dplyr::select(definition) %>%
- unique
- )
- })
- ) # end of "tagapply" -- text areas
- ) # end of bsCollapsePanel
- }
- ) # end of "tagapply" -- collapse boxes
-
- rv[[file.name]]$UI <- do.call(
- bsCollapse,
- c(
- .content,
- id = file.name,
- multiple = FALSE
- )
- )
-
- # * Write server ====
- rv[[file.name]]$obs <- sapply(
- seq(dim(rv[[file.name]]$CatVars)[1]),
- function(row) {
- input.id <- paste(
- rv[[file.name]]$CatVars$attributeName[row],
- rv[[file.name]]$CatVars$code[row] %>%
- gsub("[ [:punct:]]", "", .),
- sep = "-"
+ ) # end of "tagapply" -- collapse boxes
+
+ main.env$local.rv[[file.name]]$UI <- do.call(
+ bsCollapse,
+ c(
+ .content,
+ id = file.name,
+ multiple = FALSE
)
-
- return(
- observeEvent(input[[input.id]],
- {
- req(input[[input.id]])
- rv[[file.name]]$CatVars[row, "definition"] <- input[[input.id]]
- },
- suspended = TRUE
+ )
+
+ # * Write server ====
+ main.env$local.rv[[file.name]]$obs <- sapply(
+ seq(dim(main.env$local.rv[[file.name]]$CatVars)[1]),
+ function(row) {
+ input.id <- paste(
+ main.env$local.rv[[file.name]]$CatVars$attributeName[row],
+ main.env$local.rv[[file.name]]$CatVars$code[row] %>%
+ gsub("[ [:punct:]]", "", .),
+ sep = "-"
)
- )
- }
- )
+
+ return(
+ observeEvent(input[[input.id]],
+ {
+ req(input[[input.id]])
+ main.env$local.rv[[file.name]]$CatVars[row, "definition"] <- input[[input.id]]
+ },
+ suspended = TRUE
+ )
+ )
+ }
+ )
+ })
})
-
+
# Navigation buttons ----
# Previous file
observeEvent(input$file_prev, {
- req(rv$current.index, rv$catvar.files)
- save.variable$emlal$CatVars[[rv$current.file]] <- rv[[rv$current.file]]$CatVars
- if (rv$current.index > 1) {
- rv$current.index <- rv$current.index - 1
+ req(main.env$local.rv$current.index, main.env$local.rv$catvar.files)
+ main.env$save.variable$CatVars[[main.env$local.rv$current.file]] <- main.env$local.rv[[main.env$local.rv$current.file]]$CatVars
+ if (main.env$local.rv$current.index > 1) {
+ main.env$local.rv$current.index <- main.env$local.rv$current.index - 1
}
})
-
+
# Next file
observeEvent(input$file_next, {
- req(rv$current.index, rv$catvar.files)
- save.variable$emlal$CatVars[[rv$current.file]] <- rv[[rv$current.file]]$CatVars
- if (rv$current.index < length(rv$catvar.files)) {
- rv$current.index <- rv$current.index + 1
+ req(main.env$local.rv$current.index, main.env$local.rv$catvar.files)
+ main.env$save.variable$CatVars[[main.env$local.rv$current.file]] <- main.env$local.rv[[main.env$local.rv$current.file]]$CatVars
+ if (main.env$local.rv$current.index < length(main.env$local.rv$catvar.files)) {
+ main.env$local.rv$current.index <- main.env$local.rv$current.index + 1
}
})
-
+
# Current file
output$current_file <- renderUI({
tags$div(
- rv$current.file,
+ main.env$local.rv$current.file,
class = "ellipsis",
style = paste0(
"display: inline-block;
@@ -188,84 +193,83 @@ CatVars <- function(id, main.env) {
text-align:center;
width:100%;
background: linear-gradient(90deg, #3c8dbc ",
- round(100 * rv$current.index / length(rv$catvar.files)),
+ round(100 * main.env$local.rv$current.index / length(main.env$local.rv$catvar.files)),
"%, white ",
- round(100 * rv$current.index / length(rv$catvar.files)),
+ round(100 * main.env$local.rv$current.index / length(main.env$local.rv$catvar.files)),
"%);"
)
)
})
-
+
# Set UI ----
output$edit_catvar <- renderUI({
validate(
- need(rv[[rv$current.file]]$UI, "No UI set.")
+ need(main.env$local.rv[[main.env$local.rv$current.file]]$UI, "No UI set.")
)
- rv[[rv$current.file]]$UI
+ main.env$local.rv[[main.env$local.rv$current.file]]$UI
}) # end of renderUI
-
+
# Set Server ----
-
+
# Suspend observers
- observeEvent(rv$current.index,
+ observeEvent(main.env$local.rv$current.index,
{
- req(rv$current.file)
- sapply(rv[[rv$current.file]]$obs, function(obs) {
+ req(main.env$local.rv$current.file)
+ sapply(main.env$local.rv[[main.env$local.rv$current.file]]$obs, function(obs) {
obs$suspend()
})
},
priority = 2
)
-
+
# Run observers
- observeEvent(rv$current.file,
+ observeEvent(main.env$local.rv$current.file,
{
- req(rv$current.file)
- sapply(rv[[rv$current.file]]$obs, function(obs) {
+ req(main.env$local.rv$current.file)
+ sapply(main.env$local.main.env$local.rv[[main.env$local.rv$current.file]]$obs, function(obs) {
obs$resume()
})
},
priority = 0
)
-
+
# Saves ----
observe({
+ req(main.env$local.rv$catvar.files)
main.env$EAL$completed <- all(
- sapply(basename(rv$catvar.files), function(file.name) {
- all(sapply(rv[[file.name]]$CatVars$definition, isTruthy))
+ sapply(basename(main.env$local.rv$catvar.files), function(file.name) {
+ all(sapply(main.env$local.main.env$local.rv[[file.name]]$CatVars$definition, isTruthy))
})
)
})
-
+
# observeEvent(NSB$SAVE,
shinyjs::onclick(
"fill-wizard-save",
asis = TRUE,
- add = TRUE,
+ add = TRUE,
{
- req(utils::tail(main.env$EAL$history, 1) == "Categorical Variables")
-
- save.variable <- saveReactive(
- save.variable,
- rv = list(CatVars = rv)
- )
- })
-
+ req(utils::tail(main.env$EAL$history, 1) == "Categorical Variables")
+
+ saveReactive(main.env)
+ # save.variable = main.env$save.variable,
+ # rv = list(CatVars = rv)
+ # )
+ }
+ )
+
# Process data ----
- observeEvent(EAL$.next,
+ observeEvent(main.env$EAL$.next,
{
req(main.env$EAL$current == "Categorical Variables")
- save.variable <- saveReactive(
- save.variable,
- rv = list(CatVars = rv)
- )
+ saveReactive(main.env)
+ # save.variable = main.env$save.variable,
+ # rv = list(CatVars = rv)
+ # )
},
priority = 1,
ignoreInit = TRUE
)
-
- # Output ----
- return(save.variable)
})
}
diff --git a/R/eal_5_GeoCovInput.R b/R/eal_5_GeoCovInput.R
index 207d56c..637e6c0 100644
--- a/R/eal_5_GeoCovInput.R
+++ b/R/eal_5_GeoCovInput.R
@@ -1,10 +1,10 @@
#' @import shiny
#' @importFrom shinyjs hidden
-#'
+#'
#' @noRd
GeoCovInputUI <- function(id, site.id, rmv.id, default = NULL) {
div.id <- id
-
+
if (!is.null(default)) {
default <- as.vector(default)
def.site <- default["geographicDescription"]
@@ -22,7 +22,7 @@ GeoCovInputUI <- function(id, site.id, rmv.id, default = NULL) {
def.lat <- c(-45, 45)
def.lon <- c(-90, 90)
}
-
+
tags$div(
id = site.id,
fluidRow(
@@ -75,11 +75,11 @@ GeoCovInputUI <- function(id, site.id, rmv.id, default = NULL) {
#' @import shiny
#' @importFrom dplyr slice %>%
#' @importFrom shinyjs onclick
-#'
+#'
#' @noRd
GeoCovInput <- function(id, rv, rmv.id, site.id, ref) {
moduleServer(id, function(input, output, session) {
-
+
# Metadata acquisition ----
local.rv <- reactiveValues(
id = ref,
@@ -89,7 +89,7 @@ GeoCovInput <- function(id, rv, rmv.id, site.id, ref) {
eastBoundingCoordinate = 0,
westBoundingCoordinate = 0
)
-
+
# site description
observeEvent(input$site_description,
{
@@ -98,7 +98,7 @@ GeoCovInput <- function(id, rv, rmv.id, site.id, ref) {
},
priority = 1
)
-
+
# latitude
observeEvent(input[[paste0("lat_", site.id)]],
{
@@ -108,7 +108,7 @@ GeoCovInput <- function(id, rv, rmv.id, site.id, ref) {
},
priority = 1
)
-
+
# longitude
observeEvent(input[[paste0("lon_", site.id)]],
{
@@ -118,7 +118,7 @@ GeoCovInput <- function(id, rv, rmv.id, site.id, ref) {
},
priority = 1
)
-
+
# Metadata save ----
observeEvent(
{
@@ -132,7 +132,7 @@ GeoCovInput <- function(id, rv, rmv.id, site.id, ref) {
if (is.na(ind)) {
ind <- length(rv$id) + 1
}
-
+
# print values into rv at selected index
.actual.values <- printReactiveValues(local.rv)
rv$id <- c(rv$id, .actual.values["id"])
@@ -142,18 +142,18 @@ GeoCovInput <- function(id, rv, rmv.id, site.id, ref) {
ignoreInit = TRUE,
priority = 0
)
-
+
# Remove UI ----
shinyjs::onclick(rmv.id, {
# remove the UI
removeUI(selector = paste0("#", site.id), immediate = TRUE)
-
+
# unload the UI
ind <- match(ref, rv$id)
rv$coordinates <- rv$coordinates[-ind, ]
rv$id <- rv$id[-ind]
})
-
+
# Output ----
return(rv)
})
@@ -161,39 +161,38 @@ GeoCovInput <- function(id, rv, rmv.id, site.id, ref) {
#' @importFrom dplyr bind_rows
#' @import shiny
-#'
+#'
#' @noRd
insertGeoCovInput <- function(id, rv, ns, default = NULL) {
# !!! warning: rv = rv$custom here !!!
-
+
# initialize IDs ----
div.id <- id
site.id <- paste0("site_", div.id)
rmv.id <- paste0("rmv_", div.id)
-
+
# Proper module server ----
# create the UI
new.ui <- GeoCovInputUI(ns(div.id), site.id, rmv.id, default = default)
-
+
# insert the UI
insertUI(selector = "#inserthere", ui = new.ui)
-
+
# create the server
rv <- GeoCovInput(div.id, rv, rmv.id, site.id, id)
-
+
# Output ----
return(rv)
}
#' @importFrom stringr str_extract_all
-#'
+#'
#' @noRd
extractCoordinates <- function(
- rv,
- coord.cols,
- .pattern,
- files.data
-) {
+ rv,
+ coord.cols,
+ .pattern,
+ files.data) {
# initialize variables
if (coord.cols == "lat") {
coord.cols <- printReactiveValues(rv$columns$lat)
@@ -203,7 +202,7 @@ extractCoordinates <- function(
coord.cols <- printReactiveValues(rv$columns$lon)
coord.tags <- c("E", "W")
}
-
+
# Extract proper coordinates
coordinates <- files.data[[coord.cols["file"]]][[coord.cols["col"]]] %>% # uniformize decimal separators
sapply(.,
@@ -212,35 +211,39 @@ extractCoordinates <- function(
replacement = "."
)
coord.index <- which(grepl(.pattern, coordinates))
- coordinates <- coordinates[coord.index] %>%
- unname %>%
- as.numeric
-
- if(!is.data.frame(coordinates))
+ coordinates <- coordinates[coord.index] %>%
+ unname() %>%
+ as.numeric()
+
+ if (!is.data.frame(coordinates)) {
coordinates <- data.frame(
- coordinates, stringsAsFactors = FALSE
+ coordinates,
+ stringsAsFactors = FALSE
)
-
+ }
+
# Check for having only two columns
- if (dim(coordinates)[2] > 2)
+ if (dim(coordinates)[2] > 2) {
coordinates <- coordinates[, 1:2]
- if (dim(coordinates)[2] == 1)
+ }
+ if (dim(coordinates)[2] == 1) {
coordinates <- cbind(coordinates, coordinates)
-
+ }
+
if (dim(coordinates)[2] <= 2 && dim(coordinates)[2] > 0) {
# assign West and East / North and South to columns
coordinates[
coordinates[, 1] <= coordinates[, 2],
- ] <- rev(coordinates[
- coordinates[, 1] <= coordinates[, 2],
- ])
-
+ ] <- rev(coordinates[
+ coordinates[, 1] <= coordinates[, 2],
+ ])
+
colnames(coordinates) <- coord.tags
if (all(coordinates[, 1] <= coordinates[, 2])) {
colnames(coordinates) <- rev(coord.tags)
}
}
-
+
return(
list(
coordinates = coordinates,
diff --git a/R/eal_5_geographicCoverage.R b/R/eal_5_geographicCoverage.R
index 63f2597..6ce3d9b 100644
--- a/R/eal_5_geographicCoverage.R
+++ b/R/eal_5_geographicCoverage.R
@@ -1,6 +1,6 @@
#' @import shiny
#' @importFrom shinyjs hidden
-#'
+#'
#' @noRd
GeoCovUI <- function(id, main.env) {
return(
@@ -71,457 +71,465 @@ GeoCovUI <- function(id, main.env) {
#' @importFrom dplyr %>%
#' @importFrom EMLassemblyline template_geographic_coverage
#' @importFrom shinyjs onclick show
-#'
+#'
#' @noRd
-GeoCov <- function(id, main.env) {
- moduleServer(id, function(input, output, session){
- save.variable <- main.env$save.variable
- # Variable initialization ----
-
- # Reactive Values
- rv <- reactiveValues(
- columns = reactiveValues(
- choices = reactiveValues(
- files = "all",
- sites = NA_character_,
- coords = NA_character_
- ),
- site = reactiveValues(
- col = character(),
- file = character()
- ),
- lat = reactiveValues(
- col = character(),
- file = character()
- ),
- lon = reactiveValues(
- col = character(),
- file = character()
- ),
- complete = FALSE
- ),
- custom = reactiveValues(
- id = numeric(),
- coordinates = data.frame(
- geographicDescription = character(),
- northBoundingCoordinate = numeric(),
- southBoundingCoordinate = numeric(),
- eastBoundingCoordinate = numeric(),
- westBoundingCoordinate = numeric(),
- stringsAsFactors = FALSE
- ),
- complete = FALSE
- )
- )
- if(isTruthy(save.variable$emlal$GeoCov) &&
- isTruthy(names(save.variable$emlal$GeoCov))){
- . <- isolate(save.variable$emlal$GeoCov)
- if(names(.) == "columns"){
- rv$columns <- .$columns
- }
- if(names(.) == "custom"){
- rv$custom <- .$custom
- }
- }
-
- # Pre-fill ----
- # * Set choices ====
- columns <- lapply(
- seq_along(save.variable$emlal$Attributes),
- function(n) {
- .tmp <- paste(
- save.variable$emlal$Attributes[[n]]$attributeName,
- save.variable$emlal$DataFiles$name[n],
- sep = "///"
- )
- names(.tmp) <- save.variable$emlal$Attributes[[n]]$attributeName
- return(.tmp)
- }
- )
- names(columns) <- save.variable$emlal$DataFiles$name
-
- columns.coordinates <- lapply(
- seq_along(save.variable$emlal$Attributes),
- function(n) {
- .ind <- which(save.variable$emlal$Attributes[[n]]$class == "numeric")
-
- .tmp <- paste(
- save.variable$emlal$Attributes[[n]]$attributeName[.ind],
- save.variable$emlal$DataFiles$name[n],
- sep = "///"
- )
- names(.tmp) <- save.variable$emlal$Attributes[[n]]$attributeName[.ind]
- return(.tmp)
- }
- )
- names(columns.coordinates) <- save.variable$emlal$DataFiles$name
+GeoCov <- function(id, full.id, main.env) {
+ moduleServer(id, function(input, output, session) {
+ main.env$save.variable <- main.env$save.variable
- observeEvent(rv$columns$choices$files,
- {
- .file <- rv$columns$choices$files
-
- if(.file == "all" || length(.file) > 1){
- rv$columns$choices$sites <- columns
- rv$columns$choices$coords <- columns.coordinates
- }
- else if(length(.file) == 1){
- rv$columns$choices$sites <- columns[.file]
- rv$columns$choices$coords <- columns.coordinates[.file]
- }
- },
- label = "EAL5 file selection"
- )
-
- # * Read saved values ----
- if (isTRUE(grepl("columns", names(save.variable$emlal$GeoCov)))) {
- site.name <- save.variable$emlal$GeoCov$columns$site$col
- lat.col <- save.variable$emlal$GeoCov$columns$lat$col
- lon.col <- save.variable$emlal$GeoCov$columns$lon$col
-
- if (any(grepl(site.name, columns)))
- rv$columns$site <- save.variable$emlal$GeoCov$columns$site
- if (any(grepl(lat.col, columns.coordinates))){
- rv$columns$lat$col <- save.variable$emlal$GeoCov$columns$lat$col
- rv$columns$lat$file <- save.variable$emlal$GeoCov$columns$lat$file
- }
- if (any(grepl(lon.col, columns.coordinates))){
- rv$columns$lon$col <- save.variable$emlal$GeoCov$columns$lon$col
- rv$columns$lon$file <- save.variable$emlal$GeoCov$columns$lon$file
- }
- }
- if (isTRUE(grepl("custom", names(save.variable$emlal$GeoCov)))) {
- saved_table <- save.variable$emlal$GeoCov$custom$coordinates
- if (all(dim(saved_table) != 0)) {
- rv$custom$coordinates <- saved_table
- }
- }
+ # Variable initialization ----
- # * File ----
- observeEvent(
- {
- rv$columns$site$file
- rv$columns$lat$file
- rv$columns$lon$file
- },
- {
- .files <- c(rv$columns$site$file, rv$columns$lat$file, rv$columns$lon$file)
-
- # validity check
- if (isFALSE(all(sapply(.files, isTruthy))))
- rv$columns$choices$files <- "all"
- else
- rv$columns$choices$file <- unique(.files[which(isTruthy(.files))])
- },
- ignoreInit = TRUE,
- priority = 1,
- ignoreNULL = FALSE,
- label = "EAL5 init choices"
- )
-
- # Input management ----
- {
- # * Site description ----
- output$`site-ui` <- renderUI({
- # Set value
- if (length(rv$columns$site$col) > 0) {
- .site.name <- paste(
- rv$columns$site$col,
- rv$columns$site$file,
- sep = "///"
- )
- names(.site.name) <- rv$columns$site$col
+ # Reactive Values
+ # rv <- reactiveValues(
+ # columns = reactiveValues(
+ # choices = reactiveValues(
+ # files = "all",
+ # sites = NA_character_,
+ # coords = NA_character_
+ # ),
+ # site = reactiveValues(
+ # col = character(),
+ # file = character()
+ # ),
+ # lat = reactiveValues(
+ # col = character(),
+ # file = character()
+ # ),
+ # lon = reactiveValues(
+ # col = character(),
+ # file = character()
+ # ),
+ # complete = FALSE
+ # ),
+ # custom = reactiveValues(
+ # id = numeric(),
+ # coordinates = data.frame(
+ # geographicDescription = character(),
+ # northBoundingCoordinate = numeric(),
+ # southBoundingCoordinate = numeric(),
+ # eastBoundingCoordinate = numeric(),
+ # westBoundingCoordinate = numeric(),
+ # stringsAsFactors = FALSE
+ # ),
+ # complete = FALSE
+ # )
+ # )
+
+ main.env$pageLoad(5, {
+ req(isTruthy(main.env$save.variable$GeoCov) &&
+ isTruthy(names(main.env$save.variable$GeoCov)))
+ . <- isolate(main.env$save.variable$GeoCov)
+ if (names(.) == "columns") {
+ main.env$local.rv$columns <- .$columns
}
- else {
- .site.name <- c(None = "")
+ if (names(.) == "custom") {
+ main.env$local.rv$custom <- .$custom
}
-
- selectInput(
- NS(id, "site"),
- "Choose a column for sites:",
- c("None" = "", rv$columns$choices$sites),
- selected = .site.name
- )
})
- # Get input
- observeEvent(input$site,
+ # Pre-fill ----
+ # * Set choices ====
+ observeEvent(main.env$save.variable$Attributes,
{
- site.name <- input$site
-
- if (!isTruthy(site.name)) {
- rv$columns$site$col <- ""
- rv$columns$site$file <- ""
- }
+ # Get columns
+ columns <- lapply(
+ seq_along(main.env$save.variable$Attributes),
+ function(n) {
+ .tmp <- paste(
+ main.env$save.variable$Attributes[[n]]$attributeName,
+ main.env$save.variable$DataFiles$name[n],
+ sep = "///"
+ )
+ names(.tmp) <- main.env$save.variable$Attributes[[n]]$attributeName
+ return(.tmp)
+ }
+ )
+ names(columns) <- main.env$save.variable$DataFiles$name
- req(isTruthy(site.name))
+ # Extract "coordinatable" columns
+ columns.coordinates <- lapply(
+ seq_along(main.env$save.variable$Attributes),
+ function(n) {
+ .ind <- which(main.env$save.variable$Attributes[[n]]$class == "numeric")
- .tmp <- site.name %>%
- strsplit(., "///", TRUE) %>%
- unlist()
- rv$columns$site$col <- .tmp[1]
- rv$columns$site$file <- rv$columns$choices$file <- .tmp[2]
+ .tmp <- paste(
+ main.env$save.variable$Attributes[[n]]$attributeName[.ind],
+ main.env$save.variable$DataFiles$name[n],
+ sep = "///"
+ )
+ names(.tmp) <- main.env$save.variable$Attributes[[n]]$attributeName[.ind]
+ return(.tmp)
+ }
+ )
+ names(columns.coordinates) <- main.env$save.variable$DataFiles$name
+
+ .file <- main.env$local.rv$columns$choices$files
+
+ if (.file == "all" || length(.file) > 1) {
+ main.env$local.rv$columns$choices$sites <- columns
+ main.env$local.rv$columns$choices$coords <- columns.coordinates
+ }
+ else if (length(.file) == 1) {
+ main.env$local.rv$columns$choices$sites <- columns[.file]
+ main.env$local.rv$columns$choices$coords <- columns.coordinates[.file]
+ }
},
- ignoreInit = TRUE,
- label = "EAL5 get site"
+ label = "EAL5 file selection"
)
- # * Latitude ----
- output$`latitude-ui` <- renderUI({
- isolate({
- .lat.cols <- printReactiveValues(rv$columns$lat)
- })
-
- # Init value
- if (length(.lat.cols["col"]) > 0) {
- .lat.cols <- paste(
- .lat.cols["col"],
- .lat.cols["file"],
- sep = "///"
- )
- names(.lat.cols) <- .lat.cols["col"][1]
+ # * Read saved values ----
+ observeEvent(main.env$save.variable$GeoCov, {
+ if (isTRUE(grepl("columns", names(main.env$save.variable$GeoCov)))) {
+ site.name <- main.env$save.variable$GeoCov$columns$site$col
+ lat.col <- main.env$save.variable$GeoCov$columns$lat$col
+ lon.col <- main.env$save.variable$GeoCov$columns$lon$col
+
+ if (any(grepl(site.name, columns))) {
+ main.env$local.rv$columns$site <- main.env$save.variable$GeoCov$columns$site
+ }
+ if (any(grepl(lat.col, columns.coordinates))) {
+ main.env$local.rv$columns$lat$col <- main.env$save.variable$GeoCov$columns$lat$col
+ main.env$local.rv$columns$lat$file <- main.env$save.variable$GeoCov$columns$lat$file
+ }
+ if (any(grepl(lon.col, columns.coordinates))) {
+ main.env$local.rv$columns$lon$col <- main.env$save.variable$GeoCov$columns$lon$col
+ main.env$local.rv$columns$lon$file <- main.env$save.variable$GeoCov$columns$lon$file
+ }
}
- else {
- .lat.cols <- c(None = "")
+ if (isTRUE(grepl("custom", names(main.env$save.variable$GeoCov)))) {
+ saved_table <- main.env$save.variable$GeoCov$custom$coordinates
+ if (all(dim(saved_table) != 0)) {
+ main.env$local.rv$custom$coordinates <- saved_table
+ }
}
-
- # Update UI
- selectizeInput(
- NS(id, "latitude"),
- "Choose a column for latitude:",
- c("None" = "", rv$columns$choices$coords),
- selected = .lat.cols,
- options = list(
- maxItems = 2
- )
- )
})
- # Get input
- observeEvent(input$latitude,
+ # * File ----
+ observeEvent(
{
- latCols <- input$latitude
-
- if(!isTruthy(latCols)){
- rv$columns$lat$col <- ""
- rv$columns$lat$file <- ""
+ main.env$local.rv$columns$site$file
+ main.env$local.rv$columns$lat$file
+ main.env$local.rv$columns$lon$file
+ },
+ {
+ .files <- c(main.env$local.rv$columns$site$file, main.env$local.rv$columns$lat$file, main.env$local.rv$columns$lon$file)
+
+ # validity check
+ if (isFALSE(all(sapply(.files, isTruthy)))) {
+ main.env$local.rv$columns$choices$files <- "all"
+ } else {
+ main.env$local.rv$columns$choices$file <- unique(.files[which(isTruthy(.files))])
}
-
- req(isTruthy(latCols))
-
- .tmp <- latCols %>%
- strsplit(., "///", TRUE) %>%
- unlist()
-
- rv$columns$lat$col <- .tmp[1]
- rv$columns$lat$file <- .tmp[2]
- rv$columns$choices$file <- .tmp[2]
},
ignoreInit = TRUE,
priority = 1,
ignoreNULL = FALSE,
- label = "EAL5 get latitude"
+ label = "EAL5 init choices"
)
- # * Longitude ----
- output$`longitude-ui` <- renderUI({
- isolate({
- .lon.cols <- printReactiveValues(rv$columns$lon)
+ # Input management ----
+ {
+ # * Site description ----
+ output$`site-ui` <- renderUI({
+ # Set value
+ if (length(main.env$local.rv$columns$site$col) > 0) {
+ .site.name <- paste(
+ main.env$local.rv$columns$site$col,
+ main.env$local.rv$columns$site$file,
+ sep = "///"
+ )
+ names(.site.name) <- main.env$local.rv$columns$site$col
+ }
+ else {
+ .site.name <- c(None = "")
+ }
+
+ selectInput(
+ NS(full.id, "site"),
+ "Choose a column for sites:",
+ c("None" = "", main.env$local.rv$columns$choices$sites),
+ selected = .site.name
+ )
})
-
- # Init value
- if (length(.lon.cols["col"]) > 0) {
- .lon.cols <- paste(
- .lon.cols["col"],
- .lon.cols["file"],
- sep = "///"
+
+ # Get input
+ observeEvent(input$site,
+ {
+ site.name <- input$site
+
+ if (!isTruthy(site.name)) {
+ main.env$local.rv$columns$site$col <- ""
+ main.env$local.rv$columns$site$file <- ""
+ }
+
+ req(isTruthy(site.name))
+
+ .tmp <- site.name %>%
+ strsplit(., "///", TRUE) %>%
+ unlist()
+ main.env$local.rv$columns$site$col <- .tmp[1]
+ main.env$local.rv$columns$site$file <- main.env$local.rv$columns$choices$file <- .tmp[2]
+ },
+ ignoreInit = TRUE,
+ label = "EAL5 get site"
+ )
+
+ # * Latitude ----
+ output$`latitude-ui` <- renderUI({
+ isolate({
+ .lat.cols <- printReactiveValues(main.env$local.rv$columns$lat)
+ })
+
+ # Init value
+ if (length(.lat.cols["col"]) > 0) {
+ .lat.cols <- paste(
+ .lat.cols["col"],
+ .lat.cols["file"],
+ sep = "///"
+ )
+ names(.lat.cols) <- .lat.cols["col"][1]
+ }
+ else {
+ .lat.cols <- c(None = "")
+ }
+
+ # Update UI
+ selectizeInput(
+ NS(full.id, "latitude"),
+ "Choose a column for latitude:",
+ c("None" = "", main.env$local.rv$columns$choices$coords),
+ selected = .lat.cols,
+ options = list(
+ maxItems = 2
+ )
)
- names(.lon.cols) <- .lon.cols["col"][1]
- }
- else {
- .lon.cols <- c(None = "")
- }
-
- # Update UI
- selectizeInput(
- NS(id, "longitude"),
- "Choose a column for longitude:",
- c("None" = "", rv$columns$choices$coords),
- selected = .lon.cols,
- options = list(
- maxItems = 2
+ })
+
+ # Get input
+ observeEvent(input$latitude,
+ {
+ latCols <- input$latitude
+
+ if (!isTruthy(latCols)) {
+ main.env$local.rv$columns$lat$col <- ""
+ main.env$local.rv$columns$lat$file <- ""
+ }
+
+ req(isTruthy(latCols))
+
+ .tmp <- latCols %>%
+ strsplit(., "///", TRUE) %>%
+ unlist()
+
+ main.env$local.rv$columns$lat$col <- .tmp[1]
+ main.env$local.rv$columns$lat$file <- .tmp[2]
+ main.env$local.rv$columns$choices$file <- .tmp[2]
+ },
+ ignoreInit = TRUE,
+ priority = 1,
+ ignoreNULL = FALSE,
+ label = "EAL5 get latitude"
+ )
+
+ # * Longitude ----
+ output$`longitude-ui` <- renderUI({
+ isolate({
+ .lon.cols <- printReactiveValues(main.env$local.rv$columns$lon)
+ })
+
+ # Init value
+ if (length(.lon.cols["col"]) > 0) {
+ .lon.cols <- paste(
+ .lon.cols["col"],
+ .lon.cols["file"],
+ sep = "///"
+ )
+ names(.lon.cols) <- .lon.cols["col"][1]
+ }
+ else {
+ .lon.cols <- c(None = "")
+ }
+
+ # Update UI
+ selectizeInput(
+ NS(id, "longitude"),
+ "Choose a column for longitude:",
+ c("None" = "", main.env$local.rv$columns$choices$coords),
+ selected = .lon.cols,
+ options = list(
+ maxItems = 2
+ )
)
+ })
+
+ # Get input
+ observeEvent(input$longitude,
+ {
+ .lon.cols <- input$longitude
+
+ if (!isTruthy(.lon.cols)) {
+ main.env$local.rv$columns$lon$col <- ""
+ main.env$local.rv$columns$lon$file <- ""
+ }
+
+ req(isTruthy(.lon.cols))
+
+ .tmp <- .lon.cols %>%
+ strsplit(., "///", TRUE) %>%
+ unlist()
+
+ main.env$local.rv$columns$lon$col <- .tmp[1]
+ main.env$local.rv$columns$lon$file <- main.env$local.rv$columns$choices$file <- .tmp[2]
+ },
+ ignoreInit = TRUE,
+ priority = 1,
+ ignoreNULL = FALSE,
+ label = "EAL5 get longitude"
)
+ }
+
+ # Fill custom ----
+ # * Setup ----
+ observeEvent(main.env$local.rv$custom$coordinates, {
+ if (dim(main.env$local.rv$custom$coordinates)[1] > 0) {
+ sapply(1:nrow(main.env$local.rv$custom$coordinates), function(ind) {
+ id <- -ind
+ main.env$local.rv$custom <- insertGeoCovInput(
+ as.numeric(id), # from -n to -1
+ main.env$local.rv$custom,
+ ns,
+ default = main.env$local.rv$custom$coordinates[ind]
+ )
+ })
+ }
})
- # Get input
- observeEvent(input$longitude,
- {
- .lon.cols <- input$longitude
-
- if(!isTruthy(.lon.cols)){
- rv$columns$lon$col <- ""
- rv$columns$lon$file <- ""
- }
-
- req(isTruthy(.lon.cols))
-
- .tmp <- .lon.cols %>%
- strsplit(., "///", TRUE) %>%
- unlist()
-
- rv$columns$lon$col <- .tmp[1]
- rv$columns$lon$file <- rv$columns$choices$file <- .tmp[2]
- },
- ignoreInit = TRUE,
- priority = 1,
- ignoreNULL = FALSE,
- label = "EAL5 get longitude"
- )
- }
-
- # Fill custom ----
- # * Setup ----
- if (dim(rv$custom$coordinates)[1] > 0) {
- sapply(1:nrow(rv$custom$coordinates), function(ind) {
- id <- -ind
- rv$custom <- insertGeoCovInput(
- as.numeric(id), # from -n to -1
- rv$custom,
- ns,
- default = rv$custom$coordinates[ind]
+ # * Manage input ----
+ observeEvent(input$addui, {
+ show("slider_tips")
+ main.env$local.rv$custom <- insertGeoCovInput(
+ as.numeric(input$addui), # from 1 to n
+ main.env$local.rv$custom,
+ ns
)
})
- }
-
- # * Manage input ----
- observeEvent(input$addui, {
- show("slider_tips")
- rv$custom <- insertGeoCovInput(
- as.numeric(input$addui), # from 1 to n
- rv$custom,
- ns
- )
- })
- # Saves ----
- observeEvent(
- {
- rv$columns$site$col
- rv$columns$lat$col
- rv$columns$lon$col
- },
- {
- rv$columns$complete <- isTruthy(rv$columns$site$col) &&
- isTruthy(rv$columns$lat$col) &&
- isTruthy(rv$columns$lon$col)
- },
- ignoreNULL = FALSE
- )
-
- observeEvent(rv$custom$coordinates,
- {
- rv$custom$complete <- checkTruth(rv$custom$coordinates)
- },
- ignoreNULL = FALSE
- )
-
- observe({
- main.env$EAL$completed <- any(
- isTRUE(rv$custom$complete),
- isTRUE(rv$columns$complete)
+ # Saves ----
+ observeEvent(
+ {
+ main.env$local.rv$columns$site$col
+ main.env$local.rv$columns$lat$col
+ main.env$local.rv$columns$lon$col
+ },
+ {
+ main.env$local.rv$columns$complete <- isTruthy(main.env$local.rv$columns$site$col) &&
+ isTruthy(main.env$local.rv$columns$lat$col) &&
+ isTruthy(main.env$local.rv$columns$lon$col)
+ },
+ ignoreNULL = FALSE
)
- })
- # observeEvent(NSB$SAVE,
- shinyjs::onclick(
- "fill-wizard-save",
- asis = TRUE,
- add = TRUE,
- {
- req(utils::tail(main.env$EAL$history, 1) == "Geographic Coverage")
+ observeEvent(main.env$local.rv$custom$coordinates,
+ {
+ main.env$local.rv$custom$complete <- checkTruth(main.env$local.rv$custom$coordinates)
+ },
+ ignoreNULL = FALSE
+ )
- save.variable <- saveReactive(
- save.variable,
- rv = list(GeoCov = rv),
- main.env = main.env
+ observe({
+ main.env$EAL$completed <- any(
+ isTRUE(main.env$local.rv$custom$complete),
+ isTRUE(main.env$local.rv$columns$complete)
)
- showNotification(
- "Geographic Coverage has been saved",
- type = "message"
- )
- },
- ignoreInit = TRUE
- )
-
- # Process data ----
- # * Previous ----
- observeEvent(EAL$.prev,
- {
- req(main.env$EAL$current == "Geographic Coverage")
+ })
- if (!"Categorical Variables" %in% main.env$EAL$history) {
- main.env$EAL$page <- main.env$EAL$page - 1
+ # observeEvent(NSB$SAVE,
+ shinyjs::onclick(
+ "fill-wizard-save",
+ asis = TRUE,
+ add = TRUE,
+ {
+ req(utils::tail(main.env$EAL$history, 1) == "Geographic Coverage")
+
+ saveReactive(main.env)
+ # main.env$save.variable,
+ # content = list(GeoCov = main.env$local.rv)
+ # )
}
- },
- ignoreInit = TRUE
- )
+ # , ignoreInit = TRUE
+ )
- # * Next ----
- observeEvent(EAL$.next,
- {
- req(main.env$EAL$current == "Geographic Coverage")
+ # Process data ----
+ # * Previous ----
+ observeEvent(main.env$EAL$.prev,
+ {
+ req(main.env$EAL$current == "Geographic Coverage")
- # Create modal
- choices <- c(
- "Columns selection" = if (rv$columns$complete) "columns" else NULL,
- "Custom edition" = if (rv$custom$complete) "custom" else NULL
- )
+ if (!"Categorical Variables" %in% main.env$EAL$history) {
+ main.env$EAL$page <- main.env$EAL$page - 1
+ }
+ },
+ ignoreInit = TRUE
+ )
- req(isTruthy(choices))
+ # * Next ----
+ observeEvent(main.env$EAL$.next,
+ {
+ req(main.env$EAL$current == "Geographic Coverage")
+
+ # Create modal
+ choices <- c(
+ "Columns selection" = if (main.env$local.rv$columns$complete) "columns" else NULL,
+ "Custom edition" = if (main.env$local.rv$custom$complete) "custom" else NULL
+ )
- nextTabModal <- modalDialog(
- title = "Proceed Geographic Coverage",
- tagList(
- "You are getting ready to proceed. Please select one of the following:",
- radioButtons(
- NS(id, "method"),
- "Method for Geographic Coverage:",
- choices = choices
+ req(isTruthy(choices))
+
+ nextTabModal <- modalDialog(
+ title = "Proceed Geographic Coverage",
+ tagList(
+ "You are getting ready to proceed. Please select one of the following:",
+ radioButtons(
+ NS(id, "method"),
+ "Method for Geographic Coverage:",
+ choices = choices
+ )
+ ),
+ easyClose = FALSE,
+ footer = tagList(
+ modalButton("Cancel"),
+ actionButton(NS(id, "confirm"), "Proceed")
)
- ),
- easyClose = FALSE,
- footer = tagList(
- modalButton("Cancel"),
- actionButton(NS(id, "confirm"), "Proceed")
)
- )
- showModal(nextTabModal)
- },
- priority = 1,
- ignoreInit = TRUE
- )
-
- observeEvent(input$confirm, {
- removeModal()
- main.env$EAL$page <- 6
- EAL$tag.list <- tagList()
-
- .method <- input$method
-
- if(.method == "columns")
- rv$custom$complete <- FALSE
- if(.method == "custom")
- rv$columns$complete <- FALSE
-
- save.variable <- saveReactive(
- save.variable,
- rv = list(GeoCov = rv),
- main.env = main.env
+ showModal(nextTabModal)
+ },
+ priority = 1,
+ ignoreInit = TRUE
)
- }, ignoreInit = TRUE)
- # Output ----
- return(save.variable)
-})
+ observeEvent(input$confirm,
+ {
+ removeModal()
+ main.env$EAL$page <- 6
+ main.env$EAL$tag.list <- tagList()
+
+ .method <- input$method
+
+ if (.method == "columns") {
+ main.env$local.rv$custom$complete <- FALSE
+ }
+ if (.method == "custom") {
+ main.env$local.rv$columns$complete <- FALSE
+ }
+
+ saveReactive(main.env)
+ # main.env$save.variable,
+ # rv = list(GeoCov = rv),
+ # main.env = main.env
+ # )
+ },
+ ignoreInit = TRUE
+ )
+ })
}
diff --git a/R/eal_6_taxonomicCoverage.R b/R/eal_6_taxonomicCoverage.R
index e79225d..8737f31 100644
--- a/R/eal_6_taxonomicCoverage.R
+++ b/R/eal_6_taxonomicCoverage.R
@@ -1,6 +1,6 @@
#' @import shiny
#' @importFrom shinyjs hidden disabled
-#'
+#'
#' @noRd
TaxCovUI <- function(id, main.env) {
return(
@@ -26,12 +26,12 @@ TaxCovUI <- function(id, main.env) {
#' @importFrom dplyr %>%
#' @importFrom EMLassemblyline template_taxonomic_coverage
#' @importFrom shinyjs onclick
-#'
+#'
#' @noRd
-TaxCov <-function(id, main.env) {
- moduleServer(id, function(input, output, session){
- save.variable <- main.env$save.variable
-
+TaxCov <- function(id, full.id, main.env) {
+ moduleServer(id, function(input, output, session) {
+ main.env$save.variable <- main.env$save.variable
+
# Variable Initialization ----
rv <- reactiveValues(
taxa.table = character(),
@@ -40,108 +40,113 @@ TaxCov <-function(id, main.env) {
taxa.authority = character(),
complete = FALSE
)
-
- if (sapply(printReactiveValues(save.variable$emlal$TaxCov), checkTruth) %>% all()) {
- rv$taxa.table <- save.variable$emlal$TaxCov$taxa.table
- rv$taxa.col <- save.variable$emlal$TaxCov$taxa.col
- rv$taxa.name.type <- save.variable$emlal$TaxCov$taxa.authority
- rv$taxa.authority <- save.variable$emlal$TaxCov$taxa.authority
- }
-
+
+ main.env$pageLoad(6, {
+ if (all(sapply(printReactiveValues(main.env$save.variable$TaxCov), checkTruth))) {
+ main.env$local.rv$taxa.table <- main.env$save.variable$TaxCov$taxa.table
+ main.env$local.rv$taxa.col <- main.env$save.variable$TaxCov$taxa.col
+ main.env$local.rv$taxa.name.type <- main.env$save.variable$TaxCov$taxa.authority
+ main.env$local.rv$taxa.authority <- main.env$save.variable$TaxCov$taxa.authority
+ }
+ })
+
# Set UI ====
-
+
# * taxa.table ====
output$taxa.table <- renderUI({
isolate({
- data.files <- basename(save.variable$emlal$DataFiles$datapath)
- value <- rv$taxa.table
- if(isFALSE(value %in% data.files))
+ data.files <- basename(main.env$save.variable$DataFiles$datapath)
+ value <- main.env$local.rv$taxa.table
+ if (isFALSE(value %in% data.files)) {
value <- NULL
+ }
})
-
+
selectInput(
- NS(id, "taxa.table"),
+ NS(full.id, "taxa.table"),
"Files containing taxonomic references",
choices = data.files,
selected = value,
multiple = FALSE
)
})
-
+
# * taxa.col ====
output$taxa.col <- renderUI({
- .ind <- match(rv$taxa.table, save.variable$emlal$DataFiles$name)
- if(isTruthy(.ind)) {
- choices <- isolate(save.variable$emlal$Attributes[[.ind]]$attributeName)
- value <- isolate(rv$taxa.col)
- if(isFALSE(value %in% choices))
+ .ind <- match(main.env$local.rv$taxa.table, main.env$save.variable$DataFiles$name)
+ if (isTruthy(.ind)) {
+ choices <- isolate(main.env$save.variable$Attributes[[.ind]]$attributeName)
+ value <- isolate(main.env$local.rv$taxa.col)
+ if (isFALSE(value %in% choices)) {
value <- NULL
+ }
.embed <- tagList
}
else {
choices <- NULL
- value <- NULL
+ value <- NULL
.embed <- shinyjs::disabled
}
-
+
.embed(
selectInput(
- NS(id, "taxa.col"),
+ NS(full.id, "taxa.col"),
"Columns from selected files",
choices = choices,
selected = value
)
)
})
-
+
# * taxa.name.type ====
output$taxa.name.type <- renderUI({
isolate({
- value <- rv$taxa.name.type
- if(isTRUE(value == "both"))
+ value <- main.env$local.rv$taxa.name.type
+ if (isTRUE(value == "both")) {
value <- c("scientific", "common")
- else if(isFALSE(value %in% c("scientific", "common")))
+ } else if (isFALSE(value %in% c("scientific", "common"))) {
value <- NULL
+ }
})
-
+
checkboxGroupInput(
- NS(id, "taxa.name.type"),
+ NS(full.id, "taxa.name.type"),
"Select one or both taxonomic name notation",
c("scientific", "common"),
selected = value
)
})
-
+
# * taxa.authority ====
output$taxa.authority <- renderUI({
isolate({
taxa.authority <- main.env$FORMATS$taxa.authorities
choices <- taxa.authority$authority
- value <- if(isTruthy(rv$taxa.authority)){
+ value <- if (isTruthy(main.env$local.rv$taxa.authority)) {
taxa.authority %>%
- dplyr::filter(id == rv$taxa.authority) %>%
+ dplyr::filter(id == main.env$local.rv$taxa.authority) %>%
dplyr::select(authority)
}
})
-
+
selectInput(
- NS(id, "taxa.authority"),
+ NS(full.id, "taxa.authority"),
"Select taxonomic authority.ies",
choices = choices,
selected = value,
multiple = TRUE
)
})
-
+
# Taxonomic coverage input ----
-
+
# * Taxa files ====
observeEvent(input$taxa.table,
{
# invalid-selected/no value(s)
if (!isTruthy(input$taxa.table)) {
shinyjs::disable("taxa.col")
-
+
updateSelectizeInput(
session,
"taxa.col",
@@ -151,20 +156,21 @@ TaxCov <-function(id, main.env) {
# valid-selected value(s)
else {
shinyjs::enable("taxa.col")
-
+
taxa.col.list <- lapply(input$taxa.table, function(file) {
- all.files <- save.variable$emlal$DataFiles
+ all.files <- main.env$save.variable$DataFiles
file <- all.files[all.files$name == file, "datapath"]
df <- readDataTable(file, stringsAsFactors = FALSE)
return(colnames(df))
})
names(taxa.col.list) <- input$taxa.table
-
- .update.var <- if (isTRUE(rv$taxa.col %in% taxa.col.list))
- rv$taxa.col
- else
+
+ .update.var <- if (isTRUE(main.env$local.rv$taxa.col %in% taxa.col.list)) {
+ main.env$local.rv$taxa.col
+ } else {
NULL
-
+ }
+
updateSelectizeInput(
session,
"taxa.col",
@@ -172,60 +178,64 @@ TaxCov <-function(id, main.env) {
selected = .update.var
)
}
-
+
# save
- rv$taxa.table <- list(input$taxa.table)
- isolate({save.variable$emlal$TaxCov$taxa.table <- rv$taxa.table})
+ main.env$local.rv$taxa.table <- list(input$taxa.table)
+ isolate({
+ main.env$save.variable$TaxCov$taxa.table <- main.env$local.rv$taxa.table
+ })
},
priority = -1
)
-
+
# * Taxa columns to read ====
observeEvent(input$taxa.col, {
req(input$taxa.col)
-
- rv$taxa.col <- input$taxa.col
- isolate({save.variable$emlal$TaxCov$taxa.col <- rv$taxa.col})
+
+ main.env$local.rv$taxa.col <- input$taxa.col
+ isolate({
+ main.env$save.variable$TaxCov$taxa.col <- main.env$local.rv$taxa.col
+ })
})
-
+
# * Taxa type ====
observeEvent(input$taxa.name.type, {
req(input$taxa.name.type)
-
- rv$taxa.name.type <- input$taxa.name.type
-
- if ("scientific" %in% rv$taxa.name.type &&
- "common" %in% rv$taxa.name.type) {
- rv$taxa.name.type <- "both"
+
+ main.env$local.rv$taxa.name.type <- input$taxa.name.type
+
+ if ("scientific" %in% main.env$local.rv$taxa.name.type &&
+ "common" %in% main.env$local.rv$taxa.name.type) {
+ main.env$local.rv$taxa.name.type <- "both"
}
- save.variable$emlal$TaxCov$taxa.name.type <- rv$taxa.name.type
+ main.env$save.variable$TaxCov$taxa.name.type <- main.env$local.rv$taxa.name.type
})
-
+
# * Taxa authority ====
observeEvent(input$taxa.authority, {
req(input$taxa.authority)
-
- rv$taxa.authority <- main.env$FORMATS$taxa.authorities %>%
+
+ main.env$local.rv$taxa.authority <- main.env$FORMATS$taxa.authorities %>%
dplyr::filter(authority %in% input$taxa.authority) %>%
dplyr::select(id) %>%
unlist()
- save.variable$emlal$TaxCov$taxa.authority <- rv$taxa.authority
+ main.env$save.variable$TaxCov$taxa.authority <- main.env$local.rv$taxa.authority
})
-
+
# Saves ----
main.env$EAL$completed <- TRUE
observe({
req(main.env$EAL$current == "Taxonomic Coverage")
-
- rv$complete <- all(
- length(rv$taxa.table) > 0 &&
- length(rv$taxa.col) > 0 &&
- length(rv$taxa.name.type) > 0 &&
- length(rv$taxa.authority) > 0
+
+ main.env$local.rv$complete <- all(
+ length(main.env$local.rv$taxa.table) > 0 &&
+ length(main.env$local.rv$taxa.col) > 0 &&
+ length(main.env$local.rv$taxa.name.type) > 0 &&
+ length(main.env$local.rv$taxa.authority) > 0
)
})
-
-
+
+
# observeEvent(NSB$SAVE,
shinyjs::onclick(
"fill-wizard-save",
@@ -234,24 +244,24 @@ TaxCov <-function(id, main.env) {
{
req(utils::tail(main.env$EAL$history, 1) == "Taxonomic Coverage")
- save.variable <- saveReactive(
- save.variable = savevar,
- rv = list(TaxCov = rv)
- )
- },
- ignoreInit = TRUE
+ saveReactive(main.env)
+ # save.variable = main.env$save.variable,
+ # rv = list(TaxCov = rv)
+ # )
+ }
+ # , ignoreInit = TRUE
)
-
+
# Process data ----
- observeEvent(EAL$.next,
+ observeEvent(main.env$EAL$.next,
{
req(main.env$EAL$current == "Taxonomic Coverage")
-
+
choices <- c(
- "Yes - Taxonomic coverage will be written as file" = if (rv$complete) 1 else NULL,
+ "Yes - Taxonomic coverage will be written as file" = if (main.env$local.rv$complete) 1 else NULL,
"No - Taxonomic coverage will be left blank" = 0
)
-
+
nextTabModal <- modalDialog(
title = "Proceed Taxonomic Coverage",
tagList(
@@ -267,33 +277,33 @@ TaxCov <-function(id, main.env) {
actionButton(NS(id, "confirm"), "Proceed")
)
)
-
+
showModal(nextTabModal)
},
ignoreInit = TRUE
)
-
+
observeEvent(input$confirm, {
removeModal()
main.env$EAL$page <- 7
- EAL$tag.list <- tagList()
-
+ main.env$EAL$tag.list <- tagList()
+
# Write files
if (input$filled == "1") {
- save.variable <- saveReactive(
- save.variable,
- rv = list(TaxCov = rv)
- )
-
+ saveReactive(main.env)
+ # save.variable = main.env$save.variable,
+ # rv = list(TaxCov = rv)
+ # )
+
# Template coverage
try(
template_taxonomic_coverage(
- save.variable$emlal$SelectDP$dp.metadata.path,
- save.variable$emlal$SelectDP$dp.data.path,
- taxa.table = rv$taxa.table,
- taxa.col = rv$taxa.col,
- taxa.name.type = rv$taxa.name.type,
- taxa.authority = rv$taxa.authority
+ main.env$save.variable$SelectDP$dp.metadata.path,
+ main.env$save.variable$SelectDP$dp.data.path,
+ taxa.table = main.env$local.rv$taxa.table,
+ taxa.col = main.env$local.rv$taxa.col,
+ taxa.name.type = main.env$local.rv$taxa.name.type,
+ taxa.authority = main.env$local.rv$taxa.authority
)
)
showNotification(
@@ -308,8 +318,5 @@ TaxCov <-function(id, main.env) {
)
}
})
-
- # Output ----
- return(save.variable)
})
}
diff --git a/R/eal_7_personnel.R b/R/eal_7_personnel.R
index 96cd3a3..9b23584 100644
--- a/R/eal_7_personnel.R
+++ b/R/eal_7_personnel.R
@@ -2,7 +2,7 @@
#' @noRd
PersonnelUI <- function(id, main.env) {
ns <- NS(id)
-
+
return(
fluidPage(
fluidRow(
@@ -30,13 +30,12 @@ PersonnelUI <- function(id, main.env) {
#' @import shiny
#' @importFrom shinyjs onclick enable disable
#' @importFrom data.table fwrite
-#'
+#'
#' @noRd
-Personnel <- function(id, main.env) {
- moduleServer(id, function(input, output, session){
- save.variable <- main.env$save.variable
- ns <- session$ns
-
+Personnel <- function(id, full.id, main.env) {
+ moduleServer(id, function(input, output, session) {
+ main.env$save.variable <- main.env$save.variable
+
# Variable initialization ----
rv <- reactiveValues(
Personnel = data.frame(
@@ -58,62 +57,71 @@ Personnel <- function(id, main.env) {
stringsAsFactors = FALSE
)
)
-
- personnel.file <- dir(
- save.variable$emlal$SelectDP$dp.metadata.path,
- pattern = "ersonnel",
- full.names = TRUE
- )
- saved.table <- if (isTruthy(personnel.file)) {
- data.table::fread(personnel.file, data.table = FALSE, stringsAsFactors = FALSE)
- } else if (isTruthy(unlist(save.variable$emlal$Personnel))) {
- isolate(save.variable$emlal$Personnel)
- } else {
- NULL
- }
- saved.table[is.na(saved.table)] <- ""
- if (checkTruth(saved.table)) {
- saved.table$id <- c(
- saved.table$role[1:2],
- seq_along(saved.table$givenName)[-(1:2)]
- )
- isolate(rv$Personnel <- saved.table)
-
- sapply(rv$Personnel$id, function(rvid) {
- rv <- insertPersonnelInput(
- rvid,
- rv,
- ns,
- main.env,
- role = if (rvid %in% c("creator", "contact")) rvid,
- saved = saved.table
+
+ main.env$pageLoad(7, {
+ if (checkTruth(main.env$save.variable$SelectDP$dp.metadata.path)) {
+ personnel.file <- dir(
+ main.env$save.variable$SelectDP$dp.metadata.path,
+ pattern = "ersonnel",
+ full.names = TRUE
)
- return()
- })
- } else { # New
- rv <- insertPersonnelInput(
- "creator",
- rv,
- ns,
- main.env,
- role = "creator",
- saved = saved.table
- )
-
- rv <- insertPersonnelInput(
- "contact",
- rv,
- ns,
- main.env,
- role = "contact",
- saved = saved.table
- )
- }
-
+ saved.table <- if (isTruthy(personnel.file)) {
+ data.table::fread(
+ personnel.file,
+ data.table = FALSE,
+ stringsAsFactors = FALSE
+ )
+ } else if (isTruthy(unlist(main.env$save.variable$Personnel))) {
+ isolate(main.env$save.variable$Personnel)
+ } else {
+ NULL
+ }
+ saved.table[is.na(saved.table)] <- ""
+
+ if (checkTruth(saved.table)) {
+ saved.table$id <- c(
+ saved.table$role[1:2],
+ seq_along(saved.table$givenName)[-(1:2)]
+ )
+ isolate(main.env$local.rv$Personnel <- saved.table)
+
+ sapply(main.env$local.rv$Personnel$id, function(rvid) {
+ main.env$local.rv <- insertPersonnelInput(
+ rvid,
+ main.env$local.rv,
+ ns,
+ main.env,
+ role = if (rvid %in% c("creator", "contact")) rvid,
+ saved = saved.table
+ )
+ return()
+ })
+ } else { # New
+ rv <- insertPersonnelInput(
+ "creator",
+ rv,
+ ns,
+ main.env,
+ role = "creator",
+ saved = saved.table
+ )
+
+ rv <- insertPersonnelInput(
+ "contact",
+ rv,
+ ns,
+ main.env,
+ role = "contact",
+ saved = saved.table
+ )
+ }
+ }
+ })
+
# Fill Personnel ----
observeEvent(input$addui, {
- id <- dim(rv$Personnel[-c(1:2), ])[1] + 1
- while (as.character(id) %in% rv$Personnel$id) {
+ id <- dim(main.env$local.rv$Personnel[-c(1:2), ])[1] + 1
+ while (as.character(id) %in% main.env$local.rv$Personnel$id) {
id <- id + 1
}
rv <- insertPersonnelInput(
@@ -123,19 +131,19 @@ Personnel <- function(id, main.env) {
main.env
)
})
-
+
# Saves ----
observe({
main.env$EAL$completed <- all(
# Personnel
- isTruthy(rv$Personnel$givenName) &&
- isTruthy(rv$Personnel$surName) &&
- isTruthy(rv$Personnel$organizationName) &&
- isTruthy(rv$Personnel$electronicMailAddress) &&
- all(c("creator", "contact") %in% rv$Personnel$role)
+ isTruthy(main.env$local.rv$Personnel$givenName) &&
+ isTruthy(main.env$local.rv$Personnel$surName) &&
+ isTruthy(main.env$local.rv$Personnel$organizationName) &&
+ isTruthy(main.env$local.rv$Personnel$electronicMailAddress) &&
+ all(c("creator", "contact") %in% main.env$local.rv$Personnel$role)
)
})
-
+
# observeEvent(NSB$SAVE,
shinyjs::onclick(
"fill-wizard-save",
@@ -143,489 +151,29 @@ Personnel <- function(id, main.env) {
add = TRUE,
{
req(main.env$EAL$current == "Personnel")
-
+
# save
- save.variable <- saveReactive(
- save.variable = savevar,
- rv = list(Personnel = rv)
- )
- },
- ignoreInit = TRUE
+ saveReactive(main.env)
+ # save.variable = main.env$save.variable,
+ # rv = list(Personnel = rv)
+ # )
+ }
+ # , ignoreInit = TRUE
)
-
+
# Process data ----
- observeEvent(EAL$.next,
+ observeEvent(main.env$EAL$.next,
{
- req(checkTruth(rv$Personnel))
+ req(checkTruth(main.env$local.rv$Personnel))
req(main.env$EAL$current == "Personnel")
- save.variable <- saveReactive(
- save.variable,
- rv = list(Personnel = rv)
- )
+ saveReactive(main.env)
+ # save.variable = main.env$save.variable,
+ # rv = list(Personnel = rv)
+ # )
},
priority = 1,
ignoreInit = TRUE
)
-
- # Output ----
- return(save.variable)
- })
-}
-
-#' @import shiny
-#'
-#' @noRd
-insertPersonnelInput <- function(id, rv, ns, main.env, role = NULL, saved = NULL) {
-
- # initialize IDs ----
- div.id <- id
- site.id <- paste0("site_", id)
- rmv.id <- paste0("rmv_", id)
-
- # Proper module server ----
- # insert new UI
- newUI <- PersonnelModUI(
- NS(id, id), div.id, site.id, rmv.id,
- role = role, saved = saved
- )
- insertUI(
- selector = paste0("#", NS(id, "inserthere")),
- ui = newUI
- )
-
- # create associated server
- rv <- PersonnelMod(
- id,
- main.env, rv, # reactiveValues
- rmv.id, site.id, div.id, # renderUI ids
- role = role, saved = saved # set saved
- )
-
- # Output ----
- return(rv)
-}
-
-#' @importFrom shinyBS bsTooltip
-#'
-#' @noRd
-PersonnelModUI <- function(id, div.id, site.id, rmv.id,
- role = NULL, saved = NULL) {
-
- value <- if (checkTruth(saved)) {
- saved[saved$id == div.id, ]
- } else {
- NULL
- }
-
- # set Project Information embedding tag
- .pi.embed <- if (!is.null(role)) {
- shinyjs::hidden
- } else {
- shiny::tagList
- }
-
- tags$div(
- id = site.id,
- fluidRow(
- class = "inputBox",
- # Form ----
- # column(11,
- tagList(
- # * (ORCID) Personnel identification ----
- fluidRow(
- class = "topInputRow",
- column(
- 11,
- column(
- 4,
- if (is.null(role)) {
- selectInput(
- NS(id, "role"),
- c("creator", "PI (principal investigator)", "contact", "(other)"),
- label = withRedStar("Role"),
- selected = if (!is.null(value)) {
- if (value$role %in% c("creator", "PI (principal investigator)", "contact")) {
- value$role
- } else {
- "(other)"
- }
- } else {
- ""
- }
- )
- } else {
- tags$b(paste("Role: ", role))
- }
- ),
- column(
- 4,
- shinyjs::hidden(
- div(
- id = NS(id, "role-other"),
- textInput(
- NS(id, "role-other"),
- label = "Title of the custom role",
- value = if (!is.null(value) &&
- !value$role %in% c("creator", "PI (principal investigator)", "contact")) {
- value$role
- } else {
- ""
- }
- )
- )
- )
- ),
- column(
- 4,
- textInput(
- NS(id, "userId"),
- label = "ORCID",
- value = if (!is.null(value)) value$userId else ""
- )
- )
- ),
- column(1,
- if (is.null(role)) {
- actionButton(
- NS(id, rmv.id),
- "",
- icon("trash"),
- class = "danger"
- )
- },
- style = "padding-left: 0"
- )
- ), # end of fluidRow 1
- # * Basic identity ----
- fluidRow(
- style = "padding:5px",
- column(
- 4,
- textInput(
- NS(id, "givenName"),
- label = withRedStar("First name"),
- value = if (!is.null(value)) value$givenName else ""
- )
- ),
- column(
- 4,
- textInput(
- NS(id, "middleInitial"),
- label = "Middle initial",
- value = if (!is.null(value)) value$middleInitial else ""
- )
- ),
- column(
- 4,
- textInput(
- NS(id, "surName"),
- label = withRedStar("Last name"),
- value = if (!is.null(value)) value$surName else ""
- )
- )
- ), # end of fluidRow 1
- # * Contact ----
- fluidRow(
- style = "padding:5px",
- column(
- 8,
- textInput(
- NS(id, "organizationName"),
- label = withRedStar("Name of organization the person is associated with."),
- value = if (!is.null(value)) value$organizationName else ""
- )
- ),
- column(
- 4,
- textInput(
- NS(id, "electronicMailAddress"),
- label = withRedStar("Email address"),
- value = if (!is.null(value)) value$electronicMailAddress else ""
- )
- )
- ), # end of fluidRow 2
- # * Project information ----
- .pi.embed(
- div(
- style = "padding:5px",
- id = "project_information",
- fluidRow(
- column(
- 4,
- textInput(
- NS(id, "projectTitle"),
- label = "Project title for this dataset",
- value = if (!is.null(value)) value$projectTitle else ""
- )
- ),
- column(
- 4,
- textInput(
- NS(id, "fundingAgency"),
- label = "Entity funding the creation of this dataset",
- value = if (!is.null(value)) value$fundingAgency else ""
- )
- ),
- column(
- 4,
- textInput(
- NS(id, "fundingNumber"),
- label = "Number of the grant or award that supported creation of this dataset",
- value = if (!is.null(value)) value$fundingNumber else ""
- )
- )
- )
- )
- ) # end of project information
- )
- )
- ) # end of module div
-}
-
-#' @import shiny
-#' @importFrom rorcid as.orcid orcid_person orcid_employments orcid_email orcid_fundings
-#' @importFrom stringr str_extract
-#'
-#' @noRd
-PersonnelMod <- function(id, main.env, rv, rmv.id, site.id, ref, role = NULL, saved = NULL) {
- moduleServer(id, function(input, output, session){
- ns <- session$ns
-
- # Variable initialization ----
- if (!is.null(saved)) {
- value <- saved[saved$id == ref, ]
- } else {
- value <- NULL
- }
-
- local.rv <- reactiveValues(
- id = ref,
- # Basic Identity
- givenName = if (!is.null(value)) value$givenName else character(),
- middleInitial = if (!is.null(value)) value$middleInitial else character(),
- surName = if (!is.null(value)) value$surName else character(),
- # Contact
- organizationName = if (!is.null(value)) value$organizationName else character(),
- electronicMailAddress = if (!is.null(value)) value$electronicMailAddress else character(),
- # Personnel information
- userId = if (!is.null(value)) value$userId else character(),
- role = if (!is.null(role)) role else if (!is.null(value)) value$role else character(),
- `role-other` = if (!is.null(role)) role else if (!is.null(value)) value$`role-other` else character(),
- # Project information
- projectTitle = if (!is.null(value)) value$projectTitle else NA,
- fundingAgency = if (!is.null(value)) value$fundingAgency else NA,
- fundingNumber = if (!is.null(value)) value$fundingNumber else NA
- )
-
- # * Basic Identity ----
- name.pattern <- main.env$PATTERNS$name
-
- observeEvent(input$givenName, {
- local.rv$givenName <- if (grepl(name.pattern, input$givenName)) {
- input$givenName
- }
- })
-
- observeEvent(input$middleInitial, {
- local.rv$middleInitial <- input$middleInitial
- })
-
- observeEvent(input$surName, {
- local.rv$surName <- if (grepl(name.pattern, input$surName)) {
- input$surName
- }
- })
-
- # * Contact ----
- mail.pattern <- main.env$PATTERNS$email
-
- observeEvent(input$organizationName, {
- local.rv$organizationName <- input$organizationName
- })
-
- observeEvent(input$electronicMailAddress, {
- local.rv$electronicMailAddress <- if (grepl(mail.pattern, input$electronicMailAddress)) {
- input$electronicMailAddress
- }
- })
-
- # * (ORCID) Personnel identification ----
- orcid.pattern <- main.env$PATTERNS$ORCID
-
- observeEvent(input$userId, {
- req(input$userId)
- local.rv$userId <- input$userId
-
- if (grepl(orcid.pattern, input$userId)) {
- local.rv$userId <- stringr::str_extract(local.rv$userId, orcid.pattern)
- updateTextInput(
- session = session,
- inputId = "userId",
- value = local.rv$userId
- )
- }
-
- orcid.connect <- try(
- rorcid::as.orcid(
- local.rv$userId #TODO ORCID auth % snake
- )
- )
-
- if (
- grepl(orcid.pattern, input$userId) &&
- isTruthy(orcid.connect)
- ) {
- orcid <- local.rv$userId
- orcid.info <- list()
-
- # names
- orcid.info$names <- rorcid::orcid_person(orcid)[[orcid]]$name
- if (isTruthy(unlist(orcid.info$names$`given-names`$value))) {
- local.rv$givenName <- orcid.info$names$`given-names`$value
- updateTextInput(session, "givenName", value = local.rv$givenName)
- }
- if (isTruthy(unlist(orcid.info$names$`family-name`$value))) {
- local.rv$surName <- orcid.info$names$`family-name`$value
- updateTextInput(session, "surName", value = local.rv$surName)
- }
-
- # organization
- orcid.info$employment <- rorcid::orcid_employments(orcid)[[orcid]]$`affiliation-group`$summaries[[1]]
- if (isTruthy(unlist(orcid.info$employment$`employment-summary.organization.name`))) {
- local.rv$organizationName <- orcid.info$employment$`employment-summary.organization.name`
- updateTextInput(session, "organizationName", value = local.rv$organizationName)
- }
- if (is.null(role) &&
- isTruthy(unlist(orcid.info$employment$`employment-summary.role-title`))) {
- local.rv$role <- "(other)"
- updateTextInput(session, "role", value = local.rv$role)
- local.rv$`role-other` <- orcid.info$employment$`employment-summary.role-title`
- updateTextInput(session, "role-other", value = local.rv$`role-other`)
- }
-
- # email
- orcid.info$email <- rorcid::orcid_email(orcid)[[orcid]]$email
- if (isTruthy(unlist(orcid.info$email$email))) {
- local.rv$electronicMailAddress <- orcid.info$email$email
- updateTextInput(session, "electronicMailAddress", value = local.rv$electronicMailAddress)
- }
-
- # fundings
- if (local.rv$role == "PI (principal investigator)") {
- orcid.info$fundings <- rorcid::orcid_fundings(orcid)[[orcid]]$group$`funding-summary`[[1]]
- if (isTruthy(unlist(orcid.info$fundings$`title.title.value`))) {
- local.rv$projectTitle <- orcid.info$fundings$`title.title.value`
- updateTextInput(session, "projectTitle", value = local.rv$projectTitle)
- }
- if (isTruthy(unlist(orcid.info$fundings$`organization.name`))) {
- local.rv$fundingAgency <- orcid.info$fundings$`organization.name`
- updateTextInput(session, "fundingAgency", value = local.rv$fundingAgency)
- }
- if (isTruthy(unlist(orcid.info$fundings$`put-code`))) {
- local.rv$fundingNumber <- orcid.info$fundings$`put-code`
- updateTextInput(session, "fundingNumber", value = local.rv$fundingNumber)
- }
- }
- } else {
- showNotification(
- id = NS(id, "invalid_userid"),
- "Input 'userId' is not a valid ORCID.",
- type = "warning"
- )
- }
- })
-
- # * Project information ----
- if (is.null(role)) {
- observeEvent(
- {
- input$role
- input$`role-other`
- },
- {
- # custom role
- if (input$role == "(other)") {
- shinyjs::show("role-other")
- local.rv$role <- input$`role-other`
- } else {
- shinyjs::hide("role-other")
- local.rv$role <- input$role
- }
- # project
- if (input$role == "PI (principal investigator)") {
- shinyjs::show("projectTitle")
- shinyjs::show("fundingAgency")
- shinyjs::show("fundingNumber")
- } else {
- shinyjs::hide("projectTitle")
- shinyjs::hide("fundingAgency")
- shinyjs::hide("fundingNumber")
- }
- },
- ignoreInit = FALSE
- )
-
- observeEvent(input$projectTitle, {
- if (input$role == "PI (principal investigator)") {
- local.rv$projectTitle <- input$projectTitle
- }
- })
-
- observeEvent(input$fundingAgency, {
- if (input$role == "PI (principal investigator)") {
- local.rv$fundingAgency <- input$fundingAgency
- }
- })
-
- observeEvent(input$fundingNumber, {
- if (input$role == "PI (principal investigator)") {
- local.rv$fundingNumber <- input$fundingNumber
- }
- })
- } else {
- local.rv$role <- role
- local.rv$projectTitle <- ""
- local.rv$fundingAgency <- ""
- local.rv$fundingNumber <- ""
- }
-
- # Metadata save ----
- observe({
- req(
- !is.null(role) ||
- (any(grepl(rmv.id, names(input))) &&
- input[[rmv.id]] < 1)
- )
- personnel <- isolate(rv$Personnel)
- # Fetch correct index
- ind <- if (ref %in% personnel$id) {
- match(ref, personnel$id) # find its index
- }
- else {
- dim(personnel)[1] + 1
- }
-
- # print values into rv at selected index
- .values <- printReactiveValues(local.rv)
- .values <- .values[colnames(personnel)]
- .values[which(!sapply(.values, isTruthy))] <- ""
- isolate(rv$Personnel[ind, ] <- .values)
- })
-
- # Remove UI ----
- if (is.null(role)) {
- observeEvent(input$rmv.id, {
- # unload the RV
- ind <- match(ref, rv$Personnel$id)
- rv$Personnel <- rv$Personnel %>% slice(-ind)
-
- # remove the UI
- removeUI(selector = paste0("#", site.id), immediate = TRUE)
- })
- }
-
- # Output ----
- return(rv)
})
}
diff --git a/R/eal_7_personnel_mod.R b/R/eal_7_personnel_mod.R
new file mode 100644
index 0000000..38f3844
--- /dev/null
+++ b/R/eal_7_personnel_mod.R
@@ -0,0 +1,455 @@
+#' @import shiny
+#'
+#' @noRd
+insertPersonnelInput <- function(id, rv, ns, main.env, role = NULL, saved = NULL) {
+
+ # initialize IDs ----
+ div.id <- id
+ site.id <- paste0("site_", id)
+ rmv.id <- paste0("rmv_", id)
+
+ # Proper module server ----
+ # insert new UI
+ newUI <- PersonnelModUI(
+ NS(id, id), div.id, site.id, rmv.id,
+ role = role, saved = saved
+ )
+ insertUI(
+ selector = paste0("#", NS(id, "inserthere")),
+ ui = newUI
+ )
+
+ # create associated server
+ rv <- PersonnelMod(
+ id,
+ main.env, rv, # reactiveValues
+ rmv.id, site.id, div.id, # renderUI ids
+ role = role, saved = saved # set saved
+ )
+
+ # Output ----
+ return(rv)
+}
+
+#' @importFrom shinyBS bsTooltip
+#'
+#' @noRd
+PersonnelModUI <- function(id, div.id, site.id, rmv.id,
+ role = NULL, saved = NULL) {
+ value <- if (checkTruth(saved)) {
+ saved[saved$id == div.id, ]
+ } else {
+ NULL
+ }
+
+ # set Project Information embedding tag
+ .pi.embed <- if (!is.null(role)) {
+ shinyjs::hidden
+ } else {
+ shiny::tagList
+ }
+
+ tags$div(
+ id = site.id,
+ fluidRow(
+ class = "inputBox",
+ # Form ----
+ # column(11,
+ tagList(
+ # * (ORCID) Personnel identification ----
+ fluidRow(
+ class = "topInputRow",
+ column(
+ 11,
+ column(
+ 4,
+ if (is.null(role)) {
+ selectInput(
+ NS(id, "role"),
+ c("creator", "PI (principal investigator)", "contact", "(other)"),
+ label = withRedStar("Role"),
+ selected = if (!is.null(value)) {
+ if (value$role %in% c("creator", "PI (principal investigator)", "contact")) {
+ value$role
+ } else {
+ "(other)"
+ }
+ } else {
+ ""
+ }
+ )
+ } else {
+ tags$b(paste("Role: ", role))
+ }
+ ),
+ column(
+ 4,
+ shinyjs::hidden(
+ div(
+ id = NS(id, "role-other"),
+ textInput(
+ NS(id, "role-other"),
+ label = "Title of the custom role",
+ value = if (!is.null(value) &&
+ !value$role %in% c("creator", "PI (principal investigator)", "contact")) {
+ value$role
+ } else {
+ ""
+ }
+ )
+ )
+ )
+ ),
+ column(
+ 4,
+ textInput(
+ NS(id, "userId"),
+ label = "ORCID",
+ value = if (!is.null(value)) value$userId else ""
+ )
+ )
+ ),
+ column(1,
+ if (is.null(role)) {
+ actionButton(
+ NS(id, rmv.id),
+ "",
+ icon("trash"),
+ class = "danger"
+ )
+ },
+ style = "padding-left: 0"
+ )
+ ), # end of fluidRow 1
+ # * Basic identity ----
+ fluidRow(
+ style = "padding:5px",
+ column(
+ 4,
+ textInput(
+ NS(id, "givenName"),
+ label = withRedStar("First name"),
+ value = if (!is.null(value)) value$givenName else ""
+ )
+ ),
+ column(
+ 4,
+ textInput(
+ NS(id, "middleInitial"),
+ label = "Middle initial",
+ value = if (!is.null(value)) value$middleInitial else ""
+ )
+ ),
+ column(
+ 4,
+ textInput(
+ NS(id, "surName"),
+ label = withRedStar("Last name"),
+ value = if (!is.null(value)) value$surName else ""
+ )
+ )
+ ), # end of fluidRow 1
+ # * Contact ----
+ fluidRow(
+ style = "padding:5px",
+ column(
+ 8,
+ textInput(
+ NS(id, "organizationName"),
+ label = withRedStar("Name of organization the person is associated with."),
+ value = if (!is.null(value)) value$organizationName else ""
+ )
+ ),
+ column(
+ 4,
+ textInput(
+ NS(id, "electronicMailAddress"),
+ label = withRedStar("Email address"),
+ value = if (!is.null(value)) value$electronicMailAddress else ""
+ )
+ )
+ ), # end of fluidRow 2
+ # * Project information ----
+ .pi.embed(
+ div(
+ style = "padding:5px",
+ id = "project_information",
+ fluidRow(
+ column(
+ 4,
+ textInput(
+ NS(id, "projectTitle"),
+ label = "Project title for this dataset",
+ value = if (!is.null(value)) value$projectTitle else ""
+ )
+ ),
+ column(
+ 4,
+ textInput(
+ NS(id, "fundingAgency"),
+ label = "Entity funding the creation of this dataset",
+ value = if (!is.null(value)) value$fundingAgency else ""
+ )
+ ),
+ column(
+ 4,
+ textInput(
+ NS(id, "fundingNumber"),
+ label = "Number of the grant or award that supported creation of this dataset",
+ value = if (!is.null(value)) value$fundingNumber else ""
+ )
+ )
+ )
+ )
+ ) # end of project information
+ )
+ )
+ ) # end of module div
+}
+
+#' @import shiny
+#' @importFrom rorcid as.orcid orcid_person orcid_employments orcid_email orcid_fundings
+#' @importFrom stringr str_extract
+#'
+#' @noRd
+PersonnelMod <- function(id, main.env, rv, rmv.id, site.id, ref, role = NULL, saved = NULL) {
+ moduleServer(id, function(input, output, session) {
+ ns <- session$ns
+
+ # Variable initialization ----
+ if (!is.null(saved)) {
+ value <- saved[saved$id == ref, ]
+ } else {
+ value <- NULL
+ }
+
+ local.rv <- reactiveValues(
+ id = ref,
+ # Basic Identity
+ givenName = if (!is.null(value)) value$givenName else character(),
+ middleInitial = if (!is.null(value)) value$middleInitial else character(),
+ surName = if (!is.null(value)) value$surName else character(),
+ # Contact
+ organizationName = if (!is.null(value)) value$organizationName else character(),
+ electronicMailAddress = if (!is.null(value)) value$electronicMailAddress else character(),
+ # Personnel information
+ userId = if (!is.null(value)) value$userId else character(),
+ role = if (!is.null(role)) role else if (!is.null(value)) value$role else character(),
+ `role-other` = if (!is.null(role)) role else if (!is.null(value)) value$`role-other` else character(),
+ # Project information
+ projectTitle = if (!is.null(value)) value$projectTitle else NA,
+ fundingAgency = if (!is.null(value)) value$fundingAgency else NA,
+ fundingNumber = if (!is.null(value)) value$fundingNumber else NA
+ )
+
+ # * Basic Identity ----
+ name.pattern <- main.env$PATTERNS$name
+
+ observeEvent(input$givenName, {
+ local.rv$givenName <- if (grepl(name.pattern, input$givenName)) {
+ input$givenName
+ }
+ })
+
+ observeEvent(input$middleInitial, {
+ local.rv$middleInitial <- input$middleInitial
+ })
+
+ observeEvent(input$surName, {
+ local.rv$surName <- if (grepl(name.pattern, input$surName)) {
+ input$surName
+ }
+ })
+
+ # * Contact ----
+ mail.pattern <- main.env$PATTERNS$email
+
+ observeEvent(input$organizationName, {
+ local.rv$organizationName <- input$organizationName
+ })
+
+ observeEvent(input$electronicMailAddress, {
+ local.rv$electronicMailAddress <- if (grepl(mail.pattern, input$electronicMailAddress)) {
+ input$electronicMailAddress
+ }
+ })
+
+ # * (ORCID) Personnel identification ----
+ orcid.pattern <- main.env$PATTERNS$ORCID
+
+ observeEvent(input$userId, {
+ req(input$userId)
+ local.rv$userId <- input$userId
+
+ if (grepl(orcid.pattern, input$userId)) {
+ local.rv$userId <- stringr::str_extract(local.rv$userId, orcid.pattern)
+ updateTextInput(
+ session = session,
+ inputId = "userId",
+ value = local.rv$userId
+ )
+ }
+
+ orcid.connect <- try(
+ rorcid::as.orcid(
+ local.rv$userId # TODO ORCID auth % snake
+ )
+ )
+
+ if (
+ grepl(orcid.pattern, input$userId) &&
+ isTruthy(orcid.connect)
+ ) {
+ orcid <- local.rv$userId
+ orcid.info <- list()
+
+ # names
+ orcid.info$names <- rorcid::orcid_person(orcid)[[orcid]]$name
+ if (isTruthy(unlist(orcid.info$names$`given-names`$value))) {
+ local.rv$givenName <- orcid.info$names$`given-names`$value
+ updateTextInput(session, "givenName", value = local.rv$givenName)
+ }
+ if (isTruthy(unlist(orcid.info$names$`family-name`$value))) {
+ local.rv$surName <- orcid.info$names$`family-name`$value
+ updateTextInput(session, "surName", value = local.rv$surName)
+ }
+
+ # organization
+ orcid.info$employment <- rorcid::orcid_employments(orcid)[[orcid]]$`affiliation-group`$summaries[[1]]
+ if (isTruthy(unlist(orcid.info$employment$`employment-summary.organization.name`))) {
+ local.rv$organizationName <- orcid.info$employment$`employment-summary.organization.name`
+ updateTextInput(session, "organizationName", value = local.rv$organizationName)
+ }
+ if (is.null(role) &&
+ isTruthy(unlist(orcid.info$employment$`employment-summary.role-title`))) {
+ local.rv$role <- "(other)"
+ updateTextInput(session, "role", value = local.rv$role)
+ local.rv$`role-other` <- orcid.info$employment$`employment-summary.role-title`
+ updateTextInput(session, "role-other", value = local.rv$`role-other`)
+ }
+
+ # email
+ orcid.info$email <- rorcid::orcid_email(orcid)[[orcid]]$email
+ if (isTruthy(unlist(orcid.info$email$email))) {
+ local.rv$electronicMailAddress <- orcid.info$email$email
+ updateTextInput(session, "electronicMailAddress", value = local.rv$electronicMailAddress)
+ }
+
+ # fundings
+ if (local.rv$role == "PI (principal investigator)") {
+ orcid.info$fundings <- rorcid::orcid_fundings(orcid)[[orcid]]$group$`funding-summary`[[1]]
+ if (isTruthy(unlist(orcid.info$fundings$`title.title.value`))) {
+ local.rv$projectTitle <- orcid.info$fundings$`title.title.value`
+ updateTextInput(session, "projectTitle", value = local.rv$projectTitle)
+ }
+ if (isTruthy(unlist(orcid.info$fundings$`organization.name`))) {
+ local.rv$fundingAgency <- orcid.info$fundings$`organization.name`
+ updateTextInput(session, "fundingAgency", value = local.rv$fundingAgency)
+ }
+ if (isTruthy(unlist(orcid.info$fundings$`put-code`))) {
+ local.rv$fundingNumber <- orcid.info$fundings$`put-code`
+ updateTextInput(session, "fundingNumber", value = local.rv$fundingNumber)
+ }
+ }
+ } else {
+ showNotification(
+ id = NS(id, "invalid_userid"),
+ "Input 'userId' is not a valid ORCID.",
+ type = "warning"
+ )
+ }
+ })
+
+ # * Project information ----
+ if (is.null(role)) {
+ observeEvent(
+ {
+ input$role
+ input$`role-other`
+ },
+ {
+ # custom role
+ if (input$role == "(other)") {
+ shinyjs::show("role-other")
+ local.rv$role <- input$`role-other`
+ } else {
+ shinyjs::hide("role-other")
+ local.rv$role <- input$role
+ }
+ # project
+ if (input$role == "PI (principal investigator)") {
+ shinyjs::show("projectTitle")
+ shinyjs::show("fundingAgency")
+ shinyjs::show("fundingNumber")
+ } else {
+ shinyjs::hide("projectTitle")
+ shinyjs::hide("fundingAgency")
+ shinyjs::hide("fundingNumber")
+ }
+ },
+ ignoreInit = FALSE
+ )
+
+ observeEvent(input$projectTitle, {
+ if (input$role == "PI (principal investigator)") {
+ local.rv$projectTitle <- input$projectTitle
+ }
+ })
+
+ observeEvent(input$fundingAgency, {
+ if (input$role == "PI (principal investigator)") {
+ local.rv$fundingAgency <- input$fundingAgency
+ }
+ })
+
+ observeEvent(input$fundingNumber, {
+ if (input$role == "PI (principal investigator)") {
+ local.rv$fundingNumber <- input$fundingNumber
+ }
+ })
+ } else {
+ local.rv$role <- role
+ local.rv$projectTitle <- ""
+ local.rv$fundingAgency <- ""
+ local.rv$fundingNumber <- ""
+ }
+
+ # Metadata save ----
+ observe({
+ req(
+ !is.null(role) ||
+ (any(grepl(rmv.id, names(input))) &&
+ input[[rmv.id]] < 1)
+ )
+ personnel <- isolate(rv$Personnel)
+ # Fetch correct index
+ ind <- if (ref %in% personnel$id) {
+ match(ref, personnel$id) # find its index
+ }
+ else {
+ dim(personnel)[1] + 1
+ }
+
+ # print values into rv at selected index
+ .values <- printReactiveValues(local.rv)
+ .values <- .values[colnames(personnel)]
+ .values[which(!sapply(.values, isTruthy))] <- ""
+ isolate(rv$Personnel[ind, ] <- .values)
+ })
+
+ # Remove UI ----
+ if (is.null(role)) {
+ observeEvent(input$rmv.id, {
+ # unload the RV
+ ind <- match(ref, rv$Personnel$id)
+ rv$Personnel <- rv$Personnel %>% slice(-ind)
+
+ # remove the UI
+ removeUI(selector = paste0("#", site.id), immediate = TRUE)
+ })
+ }
+
+ # Output ----
+ return(rv)
+ })
+}
diff --git a/R/eal_8_misc.R b/R/eal_8_misc.R
index af97f6c..bdb321d 100644
--- a/R/eal_8_misc.R
+++ b/R/eal_8_misc.R
@@ -1,27 +1,28 @@
#' @import shiny
#' @importFrom tagsinput tagsTextInput
#' @importFrom data.table fread
-#'
+#'
#' @noRd
MiscUI <- function(id, main.env) {
ns <- NS(id)
-
- .metadata.path <- isolate(main.env$save.variable$emlal$SelectDP$dp.metadata.path)
-
- if(file.exists(paste0(.metadata.path, "/keywords.txt")))
+
+ .metadata.path <- isolate(main.env$save.variable$SelectDP$dp.metadata.path)
+
+ if (file.exists(paste0(.metadata.path, "/keywords.txt"))) {
keywords <- data.table::fread(
paste0(.metadata.path, "/keywords.txt"),
data.table = FALSE, stringsAsFactors = FALSE
)
- else
+ } else {
keywords <- ""
+ }
if (checkTruth(keywords)) {
kw <- keywords$keyword %>%
strsplit(split = ",") %>%
- unlist %>%
+ unlist() %>%
paste(collapse = ",")
}
-
+
return(
fluidPage(
fluidRow(
@@ -34,33 +35,35 @@ MiscUI <- function(id, main.env) {
"),
bsCollapse(
id = NS(id, "Miscs"),
-
+
# * Abstract ----
bsCollapsePanel(
title = withRedStar("Abstract"),
value = 1,
MiscellaneousUI(
NS(id, "abstract"),
- value = if(file.exists(paste0(.metadata.path, "/abstract.txt")))
+ value = if (file.exists(paste0(.metadata.path, "/abstract.txt"))) {
readPlainText(
paste0(.metadata.path, "/abstract.txt")
)
+ }
)
),
-
+
# * Methods ----
bsCollapsePanel(
title = withRedStar("Methods"),
value = 2,
MiscellaneousUI(
NS(id, "methods"),
- value = if(file.exists(paste0(.metadata.path, "/methods.txt")))
+ value = if (file.exists(paste0(.metadata.path, "/methods.txt"))) {
readPlainText(
paste0(.metadata.path, "/methods.txt")
)
+ }
)
),
-
+
# * Keywords ----
bsCollapsePanel(
title = withRedStar("Keywords"),
@@ -86,7 +89,7 @@ MiscUI <- function(id, main.env) {
)
)
),
-
+
# * Temporal coverage ----
bsCollapsePanel(
title = "Temporal coverage",
@@ -103,7 +106,7 @@ MiscUI <- function(id, main.env) {
)
)
),
-
+
# * Additional Info ----
bsCollapsePanel(
title = "Additional Info",
@@ -113,10 +116,11 @@ MiscUI <- function(id, main.env) {
help.label = tags$p(
"If you have additional information that doesn't fall under the scope of the abstract or methods (e.g. a list of research articles or theses derived from this dataset) about your dataset, you may share it here."
),
- value = if(file.exists(paste0(.metadata.path, "/additional_info.txt")))
+ value = if (file.exists(paste0(.metadata.path, "/additional_info.txt"))) {
readPlainText(
paste0(.metadata.path, "/additional_info.txt")
)
+ }
)
)
)
@@ -129,25 +133,31 @@ MiscUI <- function(id, main.env) {
#' @import shiny
#' @importFrom shinyjs onclick enable disable
#' @importFrom data.table fread
-#'
+#'
#' @noRd
-Misc <- function(id, main.env) {
- moduleServer(id, function(input, output, session){
- save.variable <- main.env$save.variable
- ns <- session$ns
-
+Misc <- function(id, full.id, main.env) {
+ moduleServer(id, function(input, output, session) {
+ main.env$save.variable <- main.env$save.variable
+
# Variable initialization ----
- kw <- fread(
- paste0(save.variable$emlal$SelectDP$dp.metadata.path, "/keywords.txt"),
- data.table = FALSE, stringsAsFactors = FALSE
- )
-
+ if (checkTruth(isolate(main.env$save.variable$SelectDP$dp.metadata.path))) {
+ kw <- fread(
+ paste0(isolate(main.env$save.variable$SelectDP$dp.metadata.path), "/keywords.txt"),
+ data.table = FALSE, stringsAsFactors = FALSE
+ )
+ } else {
+ kw <- data.frame(
+ keyword = character(),
+ keyword.thesaurus = character()
+ )
+ }
+
rv <- reactiveValues(
# Abstract
abstract = reactiveValues(
content = character(),
file = paste(
- isolate(save.variable$emlal$SelectDP$dp.metadata.path),
+ isolate(main.env$save.variable$SelectDP$dp.metadata.path),
"abstract.txt",
sep = "/"
)
@@ -156,7 +166,7 @@ Misc <- function(id, main.env) {
methods = reactiveValues(
content = character(),
file = paste(
- isolate(save.variable$emlal$SelectDP$dp.metadata.path),
+ isolate(main.env$save.variable$SelectDP$dp.metadata.path),
"methods.txt",
sep = "/"
)
@@ -172,45 +182,39 @@ Misc <- function(id, main.env) {
additional.information = reactiveValues(
content = character(),
file = paste(
- isolate(save.variable$emlal$SelectDP$dp.metadata.path),
+ isolate(main.env$save.variable$SelectDP$dp.metadata.path),
"additional_info.txt",
sep = "/"
)
)
)
-
+
# Fill ----
# * Abstract ====
- rv$abstract <- Miscellaneous(
- "abstract",
- save.variable,
- rv = rv$abstract
- )
-
+ main.env$local.rv$abstract <- Miscellaneous("abstract", main.env$save.variable, rv = rv)
+
# * Methods ====
- rv$methods <- Miscellaneous(
- "methods",
- save.variable,
- rv = rv$methods
- )
-
+ main.env$local.rv$methods <- Miscellaneous("methods", main.env$save.variable, rv = rv)
+
# * Keywords ====
observeEvent(input$keywords, {
req(input$keywords)
-
- rv$keywords$keyword <- unique(input$keywords)
-
+
+ main.env$local.rv$keywords$keyword <- unique(input$keywords) %>%
+ strsplit(",") %>%
+ unlist()
+
output$thesaurus <- renderUI({
validate(
- need(checkTruth(rv$keywords$keyword), "No keyword input")
+ need(checkTruth(main.env$local.rv$keywords$keyword), "No keyword input")
)
tagList(
- lapply(seq_along(rv$keywords$keyword), function(kid) {
- keyword <- rv$keywords$keyword[kid]
- .val <- rv$keywords$keyword.thesaurus[kid]
-
+ lapply(seq_along(main.env$local.rv$keywords$keyword), function(kid) {
+ keyword <- main.env$local.rv$keywords$keyword[kid]
+ .val <- main.env$local.rv$keywords$keyword.thesaurus[kid]
+
textInput(
- NS(id, paste0("thesaurus-for-", keyword)),
+ NS(full.id, paste0("thesaurus-for-", keyword)),
keyword,
value = if (isTruthy(.val)) .val else ""
)
@@ -218,52 +222,52 @@ Misc <- function(id, main.env) {
)
})
})
-
+
# NOTE observers are still active after being deleted
observe({
validate(
- need(rv$keywords$keyword, "No keyword input")
+ need(main.env$local.rv$keywords$keyword, "No keyword input")
)
- sapply(seq_along(rv$keywords$keyword), function(kid) {
- keyword <- rv$keywords$keyword[kid]
+ sapply(seq_along(main.env$local.rv$keywords$keyword), function(kid) {
+ keyword <- main.env$local.rv$keywords$keyword[kid]
input_id <- paste0("thesaurus-for-", keyword)
.val <- if (isTruthy(input[[input_id]])) input[[input_id]] else ""
-
- rv$keywords$keyword.thesaurus[kid] <- .val
+
+ main.env$local.rv$keywords$keyword.thesaurus[kid] <- .val
})
})
-
+
# * Temporal coverage ====
- if (!is.null(save.variable$emlal$Misc$temporal.coverage)) {
- rv$temporal.coverage <- save.variable$emlal$Misc$temporal.coverage
+ if (!is.null(isolate(main.env$save.variable$Misc$temporal.coverage))) {
+ main.env$local.rv$temporal.coverage <- main.env$save.variable$Misc$temporal.coverage
updateDateRangeInput(
session,
"temporal.coverage",
- start = rv$temporal.coverage[1],
- end = rv$temporal.coverage[2]
+ start = main.env$local.rv$temporal.coverage[1],
+ end = main.env$local.rv$temporal.coverage[2]
)
}
observeEvent(input$temporal_coverage, {
- rv$temporal.coverage <- input$temporal_coverage
+ main.env$local.rv$temporal.coverage <- input$temporal_coverage
})
-
+
# * Additional information ====
- rv$additional.information <- Miscellaneous(
+ main.env$local.rv$additional.information <- Miscellaneous(
"additional.information",
- save.variable,
- rv = rv$additional.information
+ main.env$save.variable,
+ rv = rv
)
-
+
# Saves ----
observe({
main.env$EAL$completed <- all(
- isTruthy(rv$abstract$content()) &&
- isTruthy(rv$methods$content()) &&
- isTruthy(rv$keywords$keyword) &&
- isTruthy(rv$temporal.coverage)
+ isTruthy(main.env$local.rv$abstract$content) &&
+ isTruthy(main.env$local.rv$methods$content) &&
+ isTruthy(main.env$local.rv$keywords$keyword) &&
+ isTruthy(main.env$local.rv$temporal.coverage)
)
})
-
+
# observeEvent(NSB$SAVE,
shinyjs::onclick(
"fill-wizard-save",
@@ -272,29 +276,26 @@ Misc <- function(id, main.env) {
{
req(main.env$EAL$current == "Miscellaneous")
- save.variable <- saveReactive(
- save.variable = savevar,
- rv = list(Misc = rv)
- )
- },
- ignoreInit = TRUE
+ saveReactive(main.env)
+ # save.variable = main.env$save.variable,
+ # rv = list(Misc = rv)
+ # )
+ }
+ # , ignoreInit = TRUE
)
-
+
# Process data ----
- observeEvent(EAL$.next,
+ observeEvent(main.env$EAL$.next,
{
req(main.env$EAL$current == "Miscellaneous")
- save.variable <- saveReactive(
- save.variable = savevar,
- rv = list(Misc = rv)
- )
+ saveReactive(main.env)
+ # save.variable = main.env$save.variable,
+ # rv = list(Misc = rv)
+ # )
},
priority = 1,
ignoreInit = TRUE
)
-
- # Output ----
- return(save.variable)
})
}
diff --git a/R/eal_8_miscellaneous.R b/R/eal_8_miscellaneous.R
index 005ef21..c447b23 100644
--- a/R/eal_8_miscellaneous.R
+++ b/R/eal_8_miscellaneous.R
@@ -1,9 +1,8 @@
#' @import shiny
#' @importFrom shinyFiles shinyFilesButton
-#'
+#'
#' @noRd
MiscellaneousUI <- function(id, help.label = NULL, value = "") {
-
fluidRow(
# file selection
column(
@@ -26,12 +25,12 @@ MiscellaneousUI <- function(id, help.label = NULL, value = "") {
tagList(
tags$b("Content"),
help.label,
- markdownInputUI(
- NS(id, "content"),
- label = "",
- value = value,
- preview = FALSE
- )
+ # markdownInputUI(
+ # NS(id, "content"),
+ # label = "",
+ # value = value,
+ # preview = FALSE
+ # )
)
)
) # end of fluidRow
@@ -39,45 +38,45 @@ MiscellaneousUI <- function(id, help.label = NULL, value = "") {
#' @import shiny
#' @importFrom shinyAce updateAceEditor
-#'
+#'
#' @noRd
-Miscellaneous <- function(id){
- moduleServer(id, function(id, input, output, session, save.variable, rv) {
+Miscellaneous <- function(id, save.variable, rv) {
+ moduleServer(id, function(input, output, session) {
# Get content ----
- rv$content <- markdownInput("content", preview = FALSE)
-
+ # rv[[id]]$content <- markdownInput("content", preview = FALSE)
+
# Get file ----
observeEvent(input$file,
{
req(input$file)
- rv$file <- input$file$datapath
+ rv[[id]]$file <- input$file$datapath
},
priority = 1
)
-
- observeEvent(input$file,
- {
- req(
- isTruthy(input$file) ||
- isTruthy(names(input))
- )
- updateAceEditor(
- session,
- "content-md",
- value = readPlainText(rv$file)
- )
- },
- priority = 0
- )
-
- # UI Verbose
+
+ # observeEvent(input$file,
+ # {
+ # req(
+ # isTruthy(input$file) ||
+ # isTruthy(names(input))
+ # )
+ # shinyAce::updateAceEditor(
+ # session,
+ # "content-md",
+ # value = readPlainText(rv$file)
+ # )
+ # },
+ # priority = 0
+ # )
+
+ # Verbose file selection
output$selected <- renderText({
paste(
- basename(rv$file),
- "\n(in:", dirname(rv$file), ")"
+ basename(rv[[id]]$file),
+ "\n(in:", dirname(rv[[id]]$file), ")"
)
})
-
+
# Output ----
return(rv)
})
diff --git a/R/eal_9_annotations.R b/R/eal_9_annotations.R
index e2a560a..2d28245 100644
--- a/R/eal_9_annotations.R
+++ b/R/eal_9_annotations.R
@@ -1,6 +1,6 @@
#' annotationsUI <- function(id) {
#' ns <- NS(id)
-#'
+#'
#' return(
#' tagList(
#' useShinyjs(),
@@ -23,12 +23,12 @@
#' )
#' ) # end of return
#' }
-#'
+#'
#' #' @importFrom cedarr search
#' #' @importFrom shinyjs disabled enable disable
#' annotations <- function(input, output, session, save.variable, main.env) {
#' ns <- session$ns
-#'
+#'
#' # Initialize variables ----
#' rv <- reactiveValues(
#' annotations = data.frame(
@@ -42,7 +42,7 @@
#' object.uri = character()
#' ),
#' file = paste(
-#' save.variable$emlal$SelectDP$dp.metadata.path,
+#' save.variable$SelectDP$dp.metadata.path,
#' "annotations.txt",
#' collapse = "/"
#' )
@@ -51,7 +51,7 @@
#' rv$annotations <- fread(rv$file)
#' else
#' fwrite(rv$annotations, rv$file)
-#'
+#'
#' # Set UI ----
#' # Default terms
#' # Custom terms
@@ -59,7 +59,7 @@
#' onInsertUI <- modalDialog(
#' title = "Select an element to annotate",
#' ... = tagList(
-#'
+#'
#' ),
#' footer = tagList(
#' modalButton("Cancel"),
@@ -69,9 +69,9 @@
#' ) %>% disabled
#' )
#' )
-#'
-#'
-#'
+#'
+#'
+#'
#' insertAnnot(
#' as.character(id),
#' rv,
@@ -79,38 +79,38 @@
#' main.env
#' )
#' })
-#'
+#'
#' # Process data ----
-#'
+#'
#' # Output ----
#' return(save.variable)
#' }
-#'
+#'
#' #' @title insertPersonnelInput
#' #'
#' #' @description helper function to insert PersonnelMod* functions. Calling this from
#' #' a shiny server will insert PersonnelModUI and create its server part. Provided with
#' #' features to delete them.
-#' #'
+#' #'
#' #' @import shiny
#' insertAnnotInput <- function(id, rv, ns, main.env, value = NULL) {
-#'
+#'
#' # initialize IDs ----
#' div_id <- id
#' site_id <- paste0("site_", id)
#' rmv_id <- paste0("rmv_", id)
-#'
+#'
#' # Proper module server ----
#' # insert new UI
#' newUI <- AnnotModUI(
-#' ns(id), div_id, site_id, rmv_id,
+#' ns(id), div_id, site_id, rmv_id,
#' value = value
#' )
#' insertUI(
#' selector = paste0("#", NS(id, "inserthere")),
#' ui = newUI
#' )
-#'
+#'
#' # create associated server
#' rv <- callModule(
#' AnnotMod, id, # module args
@@ -118,11 +118,11 @@
#' rmv_id, site_id, div_id, # renderUI ids
#' value = value # set saved
#' )
-#'
+#'
#' # Output ----
#' return(rv)
#' }
-#'
+#'
#' #' @title AnnotModUI
#' #'
#' #' @description module to document EML annotation
@@ -130,13 +130,13 @@
#' #' @importFrom shinyBS bsTooltip
#' AnnotModUI <- function(id, div_id, site_id, rmv_id, value = NULL) {
#' ns <- NS(id)
-#'
+#'
#' value <- if(checkTruth(value)){
#' value[value$id == div_id,]
#' } else {
#' rep(NA, 3)
#' }
-#'
+#'
#' tags$div(
#' id = site_id,
#' fluidRow(
@@ -175,7 +175,7 @@
#' )
#' )
#' }
-#'
+#'
#' #' @title AnnotMod
#' #'
#' #' @describeIn AnnotModUI
@@ -186,14 +186,14 @@
#' AnnotMod <- function(input, output, session, main.env,
#' rv, rmv_id, site_id, ref, role = NULL, saved = NULL) {
#' ns <- session$ns
-#'
+#'
#' # Variable initialization ----
#' if(!is.null(saved)){
#' value <- saved[saved$id == ref,]
#' } else {
#' value <- NULL
#' }
-#'
+#'
#' local.rv <- reactiveValues(
#' ref = ref,
#' id = if(!is.null(value)) value$id
@@ -213,7 +213,7 @@
#' object.uri = if(!is.null(value)) value$object.uri
#' else character()
#' )
-#'
+#'
#' # Display ontology access ====
#' onclick(paste0("subject_", id), {
#' local.rv <- ontoloGUI("subject", local.rv)
@@ -224,7 +224,7 @@
#' onclick(paste0("object_", id), {
#' local.rv <- ontoloGUI("object", local.rv)
#' })
-#'
+#'
#' # Metadata save ----
#' observe({
#' req(
@@ -240,25 +240,25 @@
#' else {
#' dim(personnel)[1] + 1
#' }
-#'
+#'
#' # print values into rv at selected index
#' localValues <- printReactiveValues(local.rv)
#' localValues <- localValues[colnames(personnel)]
#' localValues[which(!sapply(localValues, isTruthy))] <- ""
#' isolate(rv$Personnel[ind,] <- localValues)
#' })
-#'
+#'
#' # Remove UI====
#' if(is.null(role))
#' onclick(rmv_id, {
#' # unload the RV
#' ind <- match(ref, rv$Personnel$id)
#' rv$Personnel <- rv$Personnel %>% slice(-ind)
-#'
+#'
#' # remove the UI
#' removeUI(selector = paste0("#", site_id), immediate = TRUE)
#' })
-#'
+#'
#' # Output ----
#' return(rv)
-#' }
\ No newline at end of file
+#' }
diff --git a/R/eal_9_makeeml.R b/R/eal_9_makeeml.R
index b177ad5..48b1aba 100644
--- a/R/eal_9_makeeml.R
+++ b/R/eal_9_makeeml.R
@@ -1,10 +1,10 @@
#' @import shiny
#' @importFrom shinyjs hidden disabled
-#'
+#'
#' @noRd
MakeEMLUI <- function(id, main.env) {
ns <- NS(id)
-
+
return(
fluidPage(
fluidRow(
@@ -57,28 +57,27 @@ MakeEMLUI <- function(id, main.env) {
#' @importFrom shinyjs show enable onclick
#' @importFrom EMLassemblyline make_eml template_arguments
#' @importFrom emldown render_eml
-#'
+#'
#' @noRd
-MakeEML <- function(id, main.env) {
- moduleServer(id, function(input, output, session){
- save.variable <- main.env$save.variable
- ns <- session$ns
-
+MakeEML <- function(id, full.id, main.env) {
+ moduleServer(id, function(input, output, session) {
+ main.env$save.variable <- main.env$save.variable
+
# Variable initialization ----
out.file <- paste0(
- save.variable$emlal$SelectDP$dp.path,
+ isolate(main.env$save.variable$SelectDP$dp.path),
"/emldown/emldown.html"
)
-
+
# Make eml ----
observeEvent(input$make_eml, {
shinyjs::hide("bug_report")
req(input$make_eml)
withProgress(
{
- . <- save.variable$emlal
+ . <- main.env$save.variable
fileName <- .$SelectDP$dp_title
-
+
x <- try(
EMLassemblyline::template_arguments(
path = .$SelectDP$dp_metadata_path,
@@ -86,14 +85,14 @@ MakeEML <- function(id, main.env) {
data.table = dir(.$SelectDP$dp_data_path)
)
)
-
+
if (class(x) == "try-error") {
out <- x
out[1] <- paste("Upon templating arguments:", x)
incProgress(0.9)
} else {
incProgress(0.3)
-
+
x$path <- .$SelectDP$dp_metadata_path
x$data.path <- .$SelectDP$dp_data_path
x$eml.path <- .$SelectDP$dp_eml_path
@@ -111,13 +110,13 @@ MakeEML <- function(id, main.env) {
# TODO user id (orcid?)
x$user.id <- "UserID"
x$write.file <- TRUE
-
+
# Yet written in the files then used in make_eml
x$geographic.coordinates <- NULL
x$geographic.description <- NULL
-
+
incProgress(0.2)
-
+
.test <- 0
out <- try(
do.call(
@@ -134,14 +133,14 @@ MakeEML <- function(id, main.env) {
message = "Writing EML ...",
value = 0.1
)
-
+
valid.eml <- EML::eml_validate(
dir(
- save.variable$emlal$SelectDP$dp.eml.path,
+ main.env$save.variable$SelectDP$dp.eml.path,
full.names = TRUE
)
)
-
+
output$warnings <- renderText({
disable("publish")
disable("emldown")
@@ -159,20 +158,20 @@ MakeEML <- function(id, main.env) {
shinyjs::enable("emldown")
return(NULL)
})
-
+
if (class(out) == "try-error" ||
- isFALSE(valid.eml)) {
+ isFALSE(valid.eml)) {
shinyjs::show("bug_report")
showNotification("EML invalid", type = "error", duration = NULL)
} else {
shinyjs::hide("bug_report")
showNotification("EML written.", type = "message")
-
+
# emldown
eml.file <- dir(
- save.variable$emlal$SelectDP$dp.eml.path,
+ main.env$save.variable$SelectDP$dp.eml.path,
full.names = TRUE,
- pattern = save.variable$emlal$SelectDP$dp.title
+ pattern = main.env$save.variable$SelectDP$dp.title
)
dir.create(dirname(out.file), recursive = TRUE)
old.wd <- getwd()
@@ -189,16 +188,16 @@ MakeEML <- function(id, main.env) {
}
}
})
-
+
observeEvent(input$bug_report, {
utils::browseURL("https://github.com/earnaud/MetaShARK-v2/issues/26")
})
-
+
# emldown ----
output$download_emldown <- downloadHandler(
filename = function() {
paste(
- save.variable$emlal$SelectDP$dp.name,
+ main.env$save.variable$SelectDP$dp.name,
"_emldown.zip"
)
},
@@ -212,8 +211,5 @@ MakeEML <- function(id, main.env) {
)
}
)
-
- # Output ----
- return(save.variable)
})
}
diff --git a/R/fill-module.R b/R/fill-module.R
index e190673..dd63b30 100644
--- a/R/fill-module.R
+++ b/R/fill-module.R
@@ -1,15 +1,48 @@
#' @import shiny
-#'
+#'
#' @noRd
fillUI <- function(id, main.env) {
ns <- NS(id)
tabsetPanel(
id = NS(id, "tabs"),
- tabPanel("EAL",
+ tabPanel(
+ "EAL",
# EMLALUI(NS(id, "EAL"), main.env)
fluidPage(
style = "padding-top:2.5%;",
+ # * Top row ----
+ tags$span(
+ fluidRow(
+ div(
+ h4("EML Assembly Line"),
+ style = "float: left"
+ ),
+ div(
+ actionButton(
+ NS(id, "help"),
+ "Help",
+ icon("question-circle")
+ ),
+ actionButton(
+ NS(id, "save"),
+ "Save",
+ icon("save")
+ ), # fill-wizard-save
+ actionButton(
+ NS(id, "quit"),
+ "Quit",
+ icon("times-circle"),
+ class = "danger"
+ ), # fill-wizard-quit
+ style = "float: right;"
+ ), # fill-wizard-help
+ style = "width: 100%"
+ ),
+ # uiOutput(NS(id, "chain")),
+ style = "display: inline-flex; width: 100%"
+ ),
+ # * Pages ----
pagesUI(
NS(id, "wizard"),
parent.id = id,
@@ -26,240 +59,306 @@ fillUI <- function(id, main.env) {
}
#' @import shiny
-#'
+#'
#' @noRd
-fill <- function(id, main.env){
+fill <- function(id, main.env) {
moduleServer(id, function(input, output, session) {
+ if (main.env$dev) {
+ shinyjs::onclick(
+ "dev",
+ {
+ if (main.env$current.tab() == "fill") {
+ browser()
+ }
+ },
+ asis = TRUE
+ )
+ }
+
# Variable initialization ====
- .EAL <- main.env$EAL # local copy
- save.variable <- main.env$save.variable
steps <- isolate(main.env$VALUES$steps)
# Wizard ====
# pages change
- pagesServer(NS(id, "wizard"), steps)
+ pagesServer(NS(id, "wizard"), main.env)
# modules content
- SelectDP("SelectDP", main.env)
- DataFiles("DataFiles", main.env)
- Attributes("Attributes", main.env)
- CatVars("CatVars", main.env)
- GeoCov("GeoCov", main.env)
- TaxCov("TaxCov", main.env)
- Personnel("Personnel", main.env)
- Misc("Misc", main.env)
- MakeEML("MakeEML", main.env)
- message(NS(id, "machin"))
+ SelectDP("SelectDP", full.id = NS(id, "SelectDP"), main.env)
+ DataFiles("DataFiles", full.id = NS(id, "DataFiles"), main.env)
+ Attributes("Attributes", full.id = NS(id, "Attributes"), main.env)
+ CatVars("CatVars", full.id = NS(id, "CatVars"), main.env)
+ GeoCov("GeoCov", full.id = NS(id, "GeoCov"), main.env)
+ TaxCov("TaxCov", full.id = NS(id, "TaxCov"), main.env)
+ Personnel("Personnel", full.id = NS(id, "Personnel"), main.env)
+ Misc("Misc", full.id = NS(id, "Misc"), main.env)
+ MakeEML("MakeEML", full.id = NS(id, "MakeEML"), main.env)
- observeEvent(.EAL$page, {
- # * Navigation ====
- # set EAL variables
- if(identical(.EAL$history, character())){
- .EAL$history <- main.env$VALUES$steps[1:.EAL$page]
- .EAL$current <- main.env$VALUES$steps[.EAL$page]
- }
+ # * Wizard components server ----
+ # * Quit ----
+ {
+ # show modal on 'quit' button clicked
+ observeEvent(input$quit, {
+ req(input$quit)
+ showModal(
+ modalDialog(
+ title = "You are leaving data description.",
+ "Are you sure to leave? Some of your metadata have maybe not been saved.",
+ easyClose = FALSE,
+ footer = tagList(
+ modalButton("Cancel"),
+ actionButton(
+ NS(id, "save_quit"),
+ "Save & Quit"
+ ),
+ actionButton(
+ NS(id, "simple_quit"),
+ "Quit",
+ icon("times-circle"),
+ class = "redButton"
+ )
+ )
+ ) # end of modalDialog
+ )
+ },
+ label = "EAL quit?"
+ )
+
+ # calls saveRDS method and quits
+ observeEvent(input$save_quit, {
+ req(input$save_quit)
- # On loading DP, correct step
- isolate({
- if(.EAL$page == -1)
- .EAL$page <- match(
- utils::tail(save.variable$emlal$history,1),
- steps
- )
- })
+ # Save work at this state
+ saveReactive(main.env$save.variable)
+ },
+ label = "EAL save+quit",
+ ignoreInit = TRUE
+ )
- if (.EAL$current == "Data Files") {
+ # quits simply
+ observeEvent(input$simple_quit, {
+ req(input$quit)
+
+ removeModal()
+
+ # Clean & reset variables
+ main.env$EAL$history <- "SelectDP"
+ main.env$EAL$page <- 1
+ },
+ label = "EAL quit",
+ ignoreInit = TRUE
+ )
+ } # quit management
+
+ # * Save ----
+ observeEvent(input$save, {saveReactive(main.env)})
+
+ # Navigation ====
+ observeEvent(main.env$EAL$page, {
+ # * set EAL variables ----
+ # reset state
+ if (main.env$EAL$current == "Data Files") {
unlink(main.env$PATHS$eal.tmp)
}
- file.remove(
- list.files(
- save.variable$emlal$SelectDP$dp.data.path,
- pattern = "preview___"
- )
- )
- .EAL$current <- main.env$VALUES$steps[.EAL$page]
- if (.EAL$current == "Data Files" &&
- !dir.exists(main.env$PATHS$eal.tmp)) {
- dir.create(main.env$PATHS$eal.tmp)
+
+ # Properly change page
+ main.env$EAL$current <- main.env$VALUES$steps[main.env$EAL$page]
+
+ if (main.env$EAL$current == "Data Files") {
+ main.env$PATHS$eal.tmp <- tempdir()
}
- if (isFALSE(.EAL$completed)) {
- .EAL$completed <- TRUE
- } # trigger
- .EAL$completed <- FALSE
- EAL$tag.list <- tagList()
+ # if (isFALSE(main.env$EAL$completed)) {
+ # main.env$EAL$completed <- TRUE
+ # } # trigger
+ main.env$EAL$completed <- FALSE
+ main.env$EAL$tag.list <- tagList()
+ main.env$local.rv <- setLocalRV(main.env)
# Edition changed path -> remove excedent history
- if (!.EAL$current %in% .EAL$history) {
- .EAL$history <- c(.EAL$history, .EAL$current)
+ if (!main.env$EAL$current %in% main.env$EAL$history) {
+ main.env$EAL$history <- c(main.env$EAL$history, main.env$EAL$current)
}
# Savevar modification
- save.variable$emlal$step <- .EAL$page
- save.variable$emlal$history <- .EAL$history
+ main.env$save.variable$step <- main.env$EAL$page
+ main.env$save.variable$history <- main.env$EAL$history
- updateTabsetPanel(session, "wizard", selected = steps[to])
+ if(main.env$EAL$page > 1) {
+ shinyjs::show("help")
+ shinyjs::show("save")
+ shinyjs::show("quit")
+ } else {
+ shinyjs::hide("help")
+ shinyjs::hide("save")
+ shinyjs::hide("quit")
+ }
+ updateTabsetPanel(session, "wizard-wizard", selected = steps[main.env$EAL$page])
# * Helps ====
- EAL$help <- modalDialog(
- title = paste0(.EAL$current, " - Help"),
- switch(.EAL$page,
- # ** SelectDP ====
- tagList(
- tags$p("This module allows you to manage your", tags$strong("data packages"), ".
- A data package (aka DP) is a collection of a dataset and its associated metadata
- and resources (scripts, literature, ...). You can:"),
- tags$ul(
- tags$li("Load an existing data package among local ones (left). You
- will resume its edition at the last saved encountered step."),
- tags$li(
- "Create a new data package. You must fill in", tags$strong("three fields"),
- tags$i("Data package name"), "will be used for identifying the DP,",
- tags$i("Data package title"), "will be displayed when consulting the DP
- page once formatted (explained in last step),",
- tags$i("Data package license"), "is the license assigned to this production for
- intellectual rights properties"
- )
- ),
- tags$p("Also, notice the", tags$strong("quick"), "check box above DP name.
- Checking this box enables \"quick mode\" which will pre-fill most of the
- fields in further steps. You still will be able to edit them at your
- convenience.")
- ),
- # ** Data Files ====
- tagList(
- tags$p("This module allows you to load data files from the dataset you want to
+ {
+ main.env$EAL$help <- modalDialog(
+ title = paste0(main.env$EAL$current, " - Help"),
+ switch(main.env$EAL$page,
+ # ** SelectDP ====
+ tagList(
+ tags$p("This module allows you to manage your", tags$strong("data packages"), ".
+ A data package (aka DP) is a collection of a dataset and its associated metadata
+ and resources (scripts, literature, ...). You can:"),
+ tags$ul(
+ tags$li("Load an existing data package among local ones (left). You
+ will resume its edition at the last saved encountered step."),
+ tags$li(
+ "Create a new data package. You must fill in", tags$strong("three fields"),
+ tags$i("Data package name"), "will be used for identifying the DP,",
+ tags$i("Data package title"), "will be displayed when consulting the DP
+ page once formatted (explained in last step),",
+ tags$i("Data package license"), "is the license assigned to this production for
+ intellectual rights properties"
+ )
+ ),
+ tags$p("Also, notice the", tags$strong("quick"), "check box above DP name.
+ Checking this box enables \"quick mode\" which will pre-fill most of the
+ fields in further steps. You still will be able to edit them at your
+ convenience.")
+ ),
+ # ** Data Files ====
+ tagList(
+ tags$p("This module allows you to load data files from the dataset you want to
describe. Once uploaded, you can set:"),
- tags$ul(
- tags$li(tags$i("Content name:"), "A name for the data contained in the file (e.g. table name)."),
- tags$li(tags$i("URL:"), "If the file is accessible remotely, here is a way to reference it."),
- tags$li(tags$i("Description:"), "A short text provided to describe the file, its content,
+ tags$ul(
+ tags$li(tags$i("Content name:"), "A name for the data contained in the file (e.g. table name)."),
+ tags$li(tags$i("URL:"), "If the file is accessible remotely, here is a way to reference it."),
+ tags$li(tags$i("Description:"), "A short text provided to describe the file, its content,
relevant information about the data in the entity.")
- ),
- tags$p("To edit your selection, select files among the list with the check boxes on
+ ),
+ tags$p("To edit your selection, select files among the list with the check boxes on
their left, then click the \"Remove\" button."),
- tags$p("Recommended size per file is around 1 Gb. Such files and heavier ones might slow down the
+ tags$p("Recommended size per file is around 1 Gb. Such files and heavier ones might slow down the
app.")
- ),
- # ** Attributes ====
- tagList(
- tags$p("This module allows you to describe precisely each attribute of each file. Some of these metadata
+ ),
+ # ** Attributes ====
+ tagList(
+ tags$p("This module allows you to describe precisely each attribute of each file. Some of these metadata
are guessed from the data files. Such fields are annoted with a star (*).
For each attribute, you can set:"),
- tags$ul(
- tags$li(tags$i("Attribute Name*:"), "the name of the attribute."),
- tags$li(tags$i("Attribute Description:"), "a "),
- tags$li(tags$i("Attribute Class*:"), "the type of content in the attributes among
+ tags$ul(
+ tags$li(tags$i("Attribute Name*:"), "the name of the attribute."),
+ tags$li(tags$i("Attribute Description:"), "a "),
+ tags$li(tags$i("Attribute Class*:"), "the type of content in the attributes among
\"numeric\", \"character\", \"categorical\" and \"Date\". Categorical means a
character string with encoded values (e.g. Male/Female)."),
- tags$li(tags$i("Date format (only for Date class): how the dates of the attributes are
+ tags$li(tags$i("Date format (only for Date class): how the dates of the attributes are
written (e.g. DD-MM-YYYY).")),
- tags$li(tags$i("Unit (only for Numeric class):"), "which is the unit used for the
+ tags$li(tags$i("Unit (only for Numeric class):"), "which is the unit used for the
numeric data of the attributes. The list is huge and refers to", tags$a("STMML Scientific
units", href = "http://www.ch.ic.ac.uk/rzepa/codata2/"), ". You can also define you own unit
(see Custom Units thereafter)."),
- tags$li(tags$i("Missing Value Code:"), "a one-word code used instead of a missing value among
+ tags$li(tags$i("Missing Value Code:"), "a one-word code used instead of a missing value among
the data of the attribute currently described."),
- tags$li(tags$i("Missing Value Code Explanation:"), "a short definition of the meaning(s) given
+ tags$li(tags$i("Missing Value Code Explanation:"), "a short definition of the meaning(s) given
for the missing value code.")
- ),
- tags$h3("Custom units creation"),
- tags$p("EML allows the user to define its own units, but this require to fulfill some more
+ ),
+ tags$h3("Custom units creation"),
+ tags$p("EML allows the user to define its own units, but this require to fulfill some more
fields. However, the custom units you will have defined will be saved into the Custom Units
table at the bottom of this page. You will find the written custom units in the units selection
once they are written. To define a custom unit, chose the unit to be \"custom\". A custom
unit is defined with:"),
- tags$ul(
- tags$li(tags$i("Unit id:"), "the id of the unit (e.g. gramsPerOneThirdMeter). The unit id
+ tags$ul(
+ tags$li(tags$i("Unit id:"), "the id of the unit (e.g. gramsPerOneThirdMeter). The unit id
must validate the STMML schema."),
- tags$li(tags$i("Unit type:"), "the physical property measured by the custom unit (e.g. mass)."),
- tags$li(tags$i("Parent unit in SI:"), "from which unit among the most common one is the custom
+ tags$li(tags$i("Unit type:"), "the physical property measured by the custom unit (e.g. mass)."),
+ tags$li(tags$i("Parent unit in SI:"), "from which unit among the most common one is the custom
unit derived (e.g. gram)."),
- tags$li(tags$i("Multiplier to SI:"), "by how many has the custom unit to be multiplied to be
+ tags$li(tags$i("Multiplier to SI:"), "by how many has the custom unit to be multiplied to be
equal to its parent unit."),
- tags$li(tags$i("Unit description:"), "some additional notes about the unit, how to compute it.")
- )
- ),
- # ** Catvars ====
- tagList(
- tags$p("This module allows you to detail the categorical variables (class \"categorical\" in Attributes).
+ tags$li(tags$i("Unit description:"), "some additional notes about the unit, how to compute it.")
+ )
+ ),
+ # ** Catvars ====
+ tagList(
+ tags$p("This module allows you to detail the categorical variables (class \"categorical\" in Attributes).
For each variable, you will be able to detail each of its value by a short description.")
- ),
- # ** Geocov ====
- tagList(
- tags$p("This module allows you to define the geographic area in which the data have been produced.
+ ),
+ # ** Geocov ====
+ tagList(
+ tags$p("This module allows you to define the geographic area in which the data have been produced.
You have the choice between two methods to define geographic coverage:"),
- tags$ul(
- tags$li(
- tags$h4("Columns description (recommended)"),
- tags$p("This method asks you to choose columns in one of your files. For latitude and longitude,
+ tags$ul(
+ tags$li(
+ tags$h4("Columns description (recommended)"),
+ tags$p("This method asks you to choose columns in one of your files. For latitude and longitude,
you can select either one or two columns. If a single column contains a pair of numbers, they
will be detected. Chosing single coordinates will be considered as single sites. Chosing pairs of
coordinates will be considered as sub-areas. For each coordinate, you can select a column
containing description for each one.")
- ),
- tags$li(
- tags$h4("Custom description"),
- tags$p("With this, you will be able to define by hand each one of the sites covered by your data.")
- )
- )
- ),
- # ** Taxcov ====
- tagList(
- tags$p("This module allows you to define the taxonomical coverage of the study. You will be asked to
+ ),
+ tags$li(
+ tags$h4("Custom description"),
+ tags$p("With this, you will be able to define by hand each one of the sites covered by your data.")
+ )
+ )
+ ),
+ # ** Taxcov ====
+ tagList(
+ tags$p("This module allows you to define the taxonomical coverage of the study. You will be asked to
select columns among your files containing the species name. Also, let the app know if the taxonomic
coverage shall be written with scientific, common or both names. At last, select at least one taxonomic
authority among the ones suggested."),
- ),
- # ** Personnel ====
- tagList(
- tags$p("This module allows you to get a full list of the people who contributed to the creation of
+ ),
+ # ** Personnel ====
+ tagList(
+ tags$p("This module allows you to get a full list of the people who contributed to the creation of
this dataset. The recommended best practice is to", tags$b("use the ORCID"), "of a person. With
this and the help of {rorcid}, the app will be able to fetch all available and interesting data.
You will be able to correct this afterwards. Also, note that you must fill in the fields
for two roles: creator and contact."),
- tags$p("Suggested roles are the following:"),
- tags$ul(
- tags$li("Creator: person who contributed to produce the data."),
- tags$li("Contact: persone to contact for any question about the data."),
- tags$li("Principal investigator: person who led the creation of the dataset. Selecting this will allow
+ tags$p("Suggested roles are the following:"),
+ tags$ul(
+ tags$li("Creator: person who contributed to produce the data."),
+ tags$li("Contact: persone to contact for any question about the data."),
+ tags$li("Principal investigator: person who led the creation of the dataset. Selecting this will allow
you to fill in additional information about the project and its funding."),
- tags$li("Custom: as the list of roles is not exhaustive, feel free to add any role you consider important.")
- )
- ),
- # ** Misc ====
- tagList(
- tags$p("This module allows you to define the last details of your data package. Note that you can write
+ tags$li("Custom: as the list of roles is not exhaustive, feel free to add any role you consider important.")
+ )
+ ),
+ # ** Misc ====
+ tagList(
+ tags$p("This module allows you to define the last details of your data package. Note that you can write
some of these metadata using the markdown syntax. Here are brief descriptions of the fields:"),
- tags$ul(
- tags$li("Abstract: the abstract of the publication linked to those data."),
- tags$li("Methods: the methods used in the production of this dataset."),
- tags$li(
- "Keywords: you can type a list of keywords for your dataset. For each keyword, you can add a
+ tags$ul(
+ tags$li("Abstract: the abstract of the publication linked to those data."),
+ tags$li("Methods: the methods used in the production of this dataset."),
+ tags$li(
+ "Keywords: you can type a list of keywords for your dataset. For each keyword, you can add a
keyword thesaurus, like", tags$a("the LTER controlled vocabulary ", href = "http://vocab.lternet.edu/vocab/vocab/index.php"),
- ", which are controlled vocabulary your exact keyword originates from. Keywords thesaurus are not
+ ", which are controlled vocabulary your exact keyword originates from. Keywords thesaurus are not
required."
- ),
- tags$li("Temporal coverage: this lets you define the duration of the study during which the data have been produced."),
- tags$li("Additional information: if any information has been omitted, you can provide it here (e.g. collection metadata
+ ),
+ tags$li("Temporal coverage: this lets you define the duration of the study during which the data have been produced."),
+ tags$li("Additional information: if any information has been omitted, you can provide it here (e.g. collection metadata
from GBIF-EML).")
- )
- ),
- # ** Make EML ====
- tagList(
- tags$p("Here we are (well done) ! This is the final step to write EML. Just click the button and let the magic happen. If an
+ )
+ ),
+ # ** Make EML ====
+ tagList(
+ tags$p("Here we are (well done) ! This is the final step to write EML. Just click the button and let the magic happen. If an
error occurs, this will be displayed to the screen. In this case, do not hesitate to get in touch with the dev team."),
- tags$p("You can also use the {emldown} package to get a human-readable version of the generated EML. The button below it will
+ tags$p("You can also use the {emldown} package to get a human-readable version of the generated EML. The button below it will
let you download the result of this step.")
- )
- ),
- footer = modalButton("Close"),
- easyClose = TRUE, fade = TRUE
- )
+ )
+ ),
+ footer = modalButton("Close"),
+ easyClose = TRUE, fade = TRUE
+ )
+ }
},
- label = "EAL0 update"
+ label = "EAL0 update"
)
- # Output ====
- return(save.variable)
+
+ observeEvent(input$help, {
+ showModal(main.env$EAL$help)
+ })
+ # End ====
})
}
diff --git a/R/fill-module_saves.R b/R/fill-module_saves.R
index 0677aa1..038ec28 100644
--- a/R/fill-module_saves.R
+++ b/R/fill-module_saves.R
@@ -1,7 +1,47 @@
#' @noRd
-.saveDataFiles <- function(save.variable, rv) {
- .tmp <- isolate(rv$data.files)
+.saveSelectDP <- function(main.env){
+ content <- main.env$local.rv
+ # Save
+ main.env$save.variable$SelectDP$dp.name <- content$dp.name()
+ main.env$save.variable$SelectDP$dp.path <- paste0(
+ main.env$PATHS$eal.dp,
+ content$dp.name(),
+ "_emldp"
+ )
+ main.env$save.variable$SelectDP$dp.metadata.path <- paste(
+ save.variable$SelectDP$dp.path,
+ content$dp.name(),
+ "metadata_templates",
+ sep = "/"
+ )
+ main.env$save.variable$SelectDP$dp.data.path <- paste(
+ save.variable$SelectDP$dp.path,
+ content$dp.name(),
+ "data_objects",
+ sep = "/"
+ )
+ main.env$save.variable$SelectDP$dp.eml.path <- paste(
+ save.variable$SelectDP$dp.path,
+ content$dp.name(),
+ "eml",
+ sep = "/"
+ )
+ main.env$save.variable$SelectDP$dp.title <- content$dp.title()
+ main.env$save.variable$quick <- content$quick
+ main.env$save.variable$creator <- if(isTRUE(main.env$SETTINGS$logged))
+ main.env$SETTINGS$user
+ else
+ "public" # prefered to set it properly than only with variable
+}
+
+#' @noRd
+.saveDataFiles <- function(main.env){
+ save.variable <- main.env$save.variable
+ content <- main.env$local.rv
+
+ # Format content
+ .tmp <- isolate(content$data.files)
if (!checkTruth(.tmp)) {
.tmp <- data.frame(
name = character(),
@@ -15,7 +55,7 @@
# -- Get files data
.from <- .tmp$datapath
.to <- paste0(
- save.variable$emlal$SelectDP$dp.data.path,
+ save.variable$SelectDP$dp.data.path,
"/", .tmp$name
)
file.copy(
@@ -23,10 +63,10 @@
to = .to
)
.tmp$datapath <- .to
-
+
# -- set metadatapath
.tmp$metadatapath <- paste(
- save.variable$emlal$SelectDP$dp.metadata.path,
+ save.variable$SelectDP$dp.metadata.path,
sub(
"(.*)\\.[a-zA-Z0-9]*$",
"attributes_\\1.txt",
@@ -35,11 +75,12 @@
sep = "/"
)
}
-
.tmp[] <- lapply(.tmp, as.character)
- save.variable$emlal$DataFiles <- .tmp
- rv$data.files$datapath <- .tmp$datapath
+ # Save
+ save.variable$DataFiles <- .tmp
+ content$data.files$datapath <- .tmp$datapath
+
return(save.variable)
}
@@ -47,48 +88,55 @@
#'
#' @import shiny
#' @importFrom data.table fwrite
-.saveAttributes <- function(save.variable, rv) {
+.saveAttributes <- function(main.env){
+ save.variable <- main.env$save.variable
+ content <- main.env$local.rv
+
+ # Save
+ save.variable$Attributes <- content$tables
+ names(save.variable$Attributes) <- save.variable$DataFiles$name
+
# Write attribute tables
sapply(
- seq_along(rv$filenames),
+ seq_along(content$filenames),
function(cur_ind) {
# write filled tables
- path <- save.variable$emlal$DataFiles$metadatapath[cur_ind]
- table <- rv$tables[[cur_ind]]
+ path <- save.variable$DataFiles$metadatapath[cur_ind]
+ table <- content$tables[[cur_ind]]
data.table::fwrite(table, path, sep = "\t")
}
)
-
+
# Write Custom units
- if (checkTruth(rv$CU_Table)) {
+ if (checkTruth(content$CU_Table)) {
data.table::fwrite(
- rv$CU_Table,
- paste0(save.variable$emlal$SelectDP$dp.metadata.path, "/custom_units.txt")
+ content$CU_Table,
+ paste0(save.variable$SelectDP$dp.metadata.path, "/custom_units.txt")
)
}
- # Save
- save.variable$emlal$Attributes <- rv$tables
- names(save.variable$emlal$Attributes) <- savevar$emlal$DataFiles$name
-
return(save.variable)
}
#' @noRd
-#'
+#'
#' @importFrom data.table fwrite
-.saveCatVars <- function(save.variable, rv) {
+.saveCatVars <- function(main.env){
+ save.variable <- main.env$save.variable
+ content <- main.env$local.rv
+
sapply(rv$catvarFiles, function(file_path) {
file_name <- basename(file_path)
- save.variable$emlal$CatVars[[file_name]] <- rv[[file_name]]$CatVars
-
- .tmp <- save.variable$emlal$CatVars[[file_name]]$code == ""
- save.variable$emlal$CatVars[[file_name]]$code[.tmp] <- "NA"
+
+ # Save
+ save.variable$CatVars[[file_name]] <- content[[file_name]]$CatVars
+ .tmp <- save.variable$CatVars[[file_name]]$code == ""
+ save.variable$CatVars[[file_name]]$code[.tmp] <- "NA"
+ # Overwrite
file.remove(file_path)
-
data.table::fwrite(
- save.variable$emlal$CatVars[[file_name]],
+ save.variable$CatVars[[file_name]],
file_path,
sep = "\t"
)
@@ -98,20 +146,23 @@
}
#' @noRd
-#'
+#'
#' @importFrom data.table fwrite
#' @import shiny
-.saveGeoCov <- function(save.variable, rv, main.env) {
+.saveGeoCov <- function(main.env){
+ save.variable <- main.env$save.variable
+ content <- main.env$local.rv
+
# Initialize variables
- .method <- if (isTRUE(rv$columns$complete)) {
+ .method <- if (isTRUE(content$columns$complete)) {
"columns"
- } else if (isTRUE(rv$custom$complete)) {
+ } else if (isTRUE(content$custom$complete)) {
"custom"
} else {
""
}
- data.files <- save.variable$emlal$DataFiles$datapath
+ data.files <- save.variable$DataFiles$datapath
data.content <- lapply(data.files, readDataTable, stringsAsFactors = FALSE)
names(data.content) <- basename(data.files)
@@ -136,19 +187,19 @@
)
geocov <- NULL
-
+ save.variable$GeoCov <- reactiveValues() # reset
+
# GeoCov written if .method filled
if (.method == "columns") {
- save.variable$emlal$GeoCov <- reactiveValues() # reset
- save.variable$emlal$GeoCov$columns <- rv$columns
+ save.variable$GeoCov$columns <- content$columns
# Site
- site <- printReactiveValues(rv$columns$site)
+ site <- printReactiveValues(content$columns$site)
.geographicDescription <- .values$data.content[[site["file"]]][[site["col"]]]
# extract queried
tmp <- extractCoordinates(
- rv,
+ content,
"lat",
main.env$PATTERNS$coordinates,
.values$data.content
@@ -158,7 +209,7 @@
.latIndex <- tmp$coordIndex
tmp <- extractCoordinates(
- rv,
+ content,
"lon",
main.env$PATTERNS$coordinates,
.values$data.content
@@ -169,8 +220,8 @@
.geographicDescription <- .geographicDescription[
.latIndex[which(.latIndex %in% .lonIndex)]
- ]
-
+ ]
+
# Final
geocov <- data.frame(
geographicDescription = .geographicDescription,
@@ -182,11 +233,11 @@
)
} else if (.method == "custom") {
# save
- save.variable$emlal$GeoCov <- reactiveValues()
- save.variable$emlal$GeoCov$custom <- rv$custom
+ save.variable$GeoCov <- reactiveValues()
+ save.variable$GeoCov$custom <- content$custom
# fill
- geocov <- rv$custom$coordinates
+ geocov <- content$custom$coordinates
}
# Write data
if (!is.null(geocov) &&
@@ -196,37 +247,44 @@
data.table::fwrite(
geocov,
paste(
- save.variable$emlal$SelectDP$dp.metadata.path,
+ save.variable$SelectDP$dp.metadata.path,
"geographic_coverage.txt",
sep = "/"
),
sep = "\t"
)
}
-
+
+ # Output
return(save.variable)
}
#' @noRd
-#'
+#'
#' @import shiny
-.saveTaxCov <- function(save.variable, rv) {
- save.variable$emlal$TaxCov <- reactiveValues(
- taxa.table = rv$taxa.table,
- taxa.col = rv$taxa.col,
- taxa.name.type = rv$taxa.name.type,
- taxa.authority = rv$taxa.authority
- )
+.saveTaxCov <- function(main.env){
+ save.variable <- main.env$save.variable
+ content <- main.env$local.rv
+
+ # Save
+ save.variable$TaxCov$taxa.table <- content$taxa.table
+ save.variable$TaxCov$taxa.col <- content$taxa.col
+ save.variable$TaxCov$taxa.name.type <- content$taxa.name.type
+ save.variable$TaxCov$taxa.authority <- content$taxa.authority
+ # Output
return(save.variable)
}
#' @noRd
-#'
+#'
#' @importFrom data.table fwrite
-.savePersonnel <- function(save.variable, rv) {
- # save
- save.variable$emlal$Personnel <- rv$Personnel
+.savePersonnel <- function(main.env){
+ save.variable <- main.env$save.variable
+ content <- main.env$local.rv
+
+ # Save
+ save.variable$Personnel <- content$Personnel
# prettify
cols <- c(
@@ -235,13 +293,13 @@
"userId", "role",
"projectTitle", "fundingAgency", "fundingNumber"
)
- personnel <- rv$Personnel[names(rv$Personnel) %in% cols]
+ personnel <- content$Personnel[names(content$Personnel) %in% cols]
- # write file
+ # File template for personnel
data.table::fwrite(
personnel,
paste0(
- save.variable$emlal$SelectDP$dp.metadata.path,
+ save.variable$SelectDP$dp.metadata.path,
"/personnel.txt"
),
sep = "\t"
@@ -251,61 +309,43 @@
}
#' @noRd
-#'
+#'
#' @importFrom data.table fwrite
#' @import shiny
-.saveMisc <- function(save.variable, rv) {
- withProgress(
- {
- save.variable$emlal$Misc <- rv
-
- setProgress(
- value = 0.25,
- message = "Writing 'abstract.txt'."
- )
- write.text(
- rv$abstract$content(),
- rv$abstract$file
- )
-
- setProgress(
- value = 0.5,
- "Writing 'methods.txt'."
- )
- write.text(
- rv$methods$content(),
- rv$methods$file
- )
-
- setProgress(
- value = 0.75,
- "Writing 'keywords.txt'."
- )
- data.table::fwrite(
- data.frame(
- keyword = rv$keywords$keyword,
- keywordThesaurus = rv$keywords$keywordThesaurus
- ),
- paste0(
- save.variable$emlal$SelectDP$dp.metadata.path,
- "/keywords.txt"
- ),
- sep = "\t"
- )
-
- setProgress(
- value = 0.99,
- "Writing 'additional_info.txt'."
- )
- write.text(
- rv$additional_information$content(),
- rv$additional_information$file
- )
-
- incProgress(0.01)
- },
- message = "Processing Miscellaneous."
+.saveMisc <- function(main.env){
+ save.variable <- main.env$save.variable
+ content <- main.env$local.rv
+
+ # save
+ save.variable$Misc <- content
+
+ # Fill template for abstract
+ write.text(
+ content$abstract$content(),
+ content$abstract$file
)
-
+ # Fill template for methods
+ write.text(
+ content$methods$content(),
+ content$methods$file
+ )
+ # Fill template for keywords
+ data.table::fwrite(
+ data.frame(
+ keyword = content$keywords$keyword,
+ keywordThesaurus = content$keywords$keywordThesaurus
+ ),
+ paste0(
+ save.variable$SelectDP$dp.metadata.path,
+ "/keywords.txt"
+ ),
+ sep = "\t"
+ )
+ # Fill template for additional information
+ write.text(
+ content$additional_information$content(),
+ content$additional_information$file
+ )
+
return(save.variable)
}
diff --git a/R/fill_pages.R b/R/fill_pages.R
index 143d2ac..2782272 100644
--- a/R/fill_pages.R
+++ b/R/fill_pages.R
@@ -3,40 +3,38 @@
#' @noRd
#'
#' @import shiny
-tabPage <- function(title, ui, navTagList = NULL){
+tabPage <- function(id, title, ui, navTagList = NULL) {
tabPanelBody(
- value = title,
- tags$span(
- div("EML Assembly Line", style = "padding-right: 15px"),
- # uiOutput(NS(id, "chain")),
- style = "display: inline-flex"
- ),
- if(is.null(navTagList))
+ value = title,
+ if (is.null(navTagList)) {
fluidRow(
column(12, ui)
)
- else
+ } else {
fluidRow(
column(10, ui),
column(2, navTagList)
)
+ }
)
}
#' @import shiny
#'
#' @noRd
-pagesUI <- function(id, parent.id, main.env){
+pagesUI <- function(id, parent.id, main.env) {
steps <- isolate(main.env$VALUES$steps)
.nb <- length(steps)
-
.ui.args <- vector("list", .nb)
+
+ # Wizard UI: a hidden tabSetPanel
sapply(
seq_along(steps),
function(i, main.env) {
page <- steps[i]
.ui.args[[i]] <<- tabPage(
+ id = id, # namespace extension
title = page,
ui = do.call(
what = switch(i,
@@ -55,72 +53,87 @@ pagesUI <- function(id, parent.id, main.env){
main.env = main.env
)
),
- navTagList = if (i > 1)
+ navTagList = if (i > 1) {
tagList(
- quitButton(id),
- saveButton(id),
if (i != 2) prevTabButton(id, i),
if (i != .nb) nextTabButton(id, i),
- uiOutput(NS(id,"tag.list")),
- tags$hr(),
- actionButton(NS(id, "help"), "Help", icon("question-circle"))
+ uiOutput(NS(i, "tag_list"))
)
- else
+ } else {
NULL
+ }
)
},
- main.env = main.env)
+ main.env = main.env
+ )
- .ui.args$id = NS(id, "wizard")
- .ui.args$type = "hidden"
+ .ui.args$id <- NS(id, "wizard")
+ .ui.args$type <- "hidden"
do.call("tabsetPanel", .ui.args)
}
# Server ====
-#' @noRd
-#'
-#' @import shiny
-changePage <- function(from, to) {
- observeEvent(input[[paste(from, to, sep = "_")]], {
- EAL$page <- EAL$page + to - from
- if(to > from)
- EAL$.next <- .EAL$.next+1
- if(from > to)
- EAL$.prev <- .EAL$.prev+1
- })
-}
-
#' Wizard pages server
-#'
+#'
#' @noRd
-pagesServer <- function(id, steps) {
+pagesServer <- function(id, main.env) {
moduleServer(id, function(input, output, session) {
- steps <- main.env$VALUES$steps
- EAL <- main.env$EAL
+ steps <- isolate(main.env$VALUES$steps)
+ changePage <- function(from, to, input, main.env) {
+ observeEvent(input[[paste(from, to, sep = "_")]], {
+ main.env$EAL$page <- main.env$EAL$page + to - from
+ if (to > from) {
+ main.env$EAL$.next <- main.env$EAL$.next + 1
+ }
+ if (from > to) {
+ main.env$EAL$.prev <- main.env$EAL$.prev + 1
+ }
+ })
+ }
+
+ completeToggle <- function(from, to, main.env) {
+ observeEvent(main.env$EAL$completed, {
+ if(isTRUE(main.env$EAL$completed))
+ enable(paste(from, to, sep = "_"))
+ else
+ disable(paste(from, to, sep = "_"))
+ })
+ }
+
+ # * Servers ====
ids <- seq_along(steps)
- lapply(ids[-1], function(i) onQuit(i)) # modules
- # lapply(ids[-1], function(i) onSave(i)) # modules -- managed into modules
- lapply(ids[-1], function(i) changePage(i, i-1)) # observers
- lapply(ids[-length(steps)], function(i) changePage(i, i+1)) # observers
+ # Generate observers
+ # Previous page
+ lapply(ids[-1], function(i)
+ changePage(i, i-1, input, main.env)
+ )
+ # Next page
+ lapply(ids[-length(steps)], function(i) {
+ changePage(i, i+1, input, main.env)
+ completeToggle(i, i+1, main.env)
+ })
# * Side UI ====
- output$tag.list <- renderUI(EAL$tag.list)
+ lapply(ids, function(i) {
+ output[[NS(i, "tag_list")]] <- renderUI(main.env$EAL$tag.list)
+ })
# * Chain ====
+ # TODO fun things to use: bsButton() bsTooltip()
# output$chain <- renderUI({
# validate(
- # need(.EAL$page > 1, "")
+ # need(main.env$EAL$page > 1, "")
# )
- #
+ #
# return(
# tags$span(
# tagList(
- # lapply(seq(.EAL$history)[-1], function(ind) {
- # .step.name <- .EAL$history[ind]
- #
+ # lapply(seq(main.env$EAL$history)[-1], function(ind) {
+ # .step.name <- main.env$EAL$history[ind]
+ #
# if (.step.name != "Taxonomic Coverage") {
# .style <- "color: dodgerblue;"
# .description <- paste(.step.name, "(mandatory)")
@@ -128,12 +141,12 @@ pagesServer <- function(id, steps) {
# .style <- "color: lightseagreen;"
# .description <- paste(.step.name, "(facultative)")
# }
- #
+ #
# return(
# actionLink(
# ns(paste0("chain_", .step.name)),
# "",
- # if (.step.name == .EAL$current) {
+ # if (.step.name == main.env$EAL$current) {
# icon("map-marker")
# } else {
# icon("circle")
@@ -147,16 +160,16 @@ pagesServer <- function(id, steps) {
# ) # end of return
# }),
# paste0(
- # "Step ", .EAL$page,
+ # "Step ", main.env$EAL$page,
# "/", length(steps),
- # ": ", .EAL$current
+ # ": ", main.env$EAL$current
# )
# ),
# style = "position: right"
# )
# )
# })
- #
+ #
# observe({
# validate(
# need(
@@ -164,162 +177,52 @@ pagesServer <- function(id, steps) {
# "Not initialized"
# ),
# need(
- # isTruthy(.EAL$history),
+ # isTruthy(main.env$EAL$history),
# "No history available"
# ),
# need(
# any(sapply(
- # .EAL$history,
+ # main.env$EAL$history,
# grepl,
# x = names(input)
# ) %>% unlist()) &&
- # length(.EAL$history) > 1,
+ # length(main.env$EAL$history) > 1,
# "No history available"
# )
# )
- #
- # sapply(seq(.EAL$history)[-1], function(.ind) {
- # id <- paste0("chain_", .EAL$history[.ind])
- #
+ #
+ # sapply(seq(main.env$EAL$history)[-1], function(.ind) {
+ # id <- paste0("chain_", main.env$EAL$history[.ind])
+ #
# observeEvent(input[[id]], {
- # req(input[[id]] && .ind != .EAL$page)
- # .EAL$page <- .ind
+ # req(input[[id]] && .ind != main.env$EAL$page)
+ # main.env$EAL$page <- .ind
# saveReactive() # Set this up correctly
- #
+ #
# # trigger changes
- # if(.ind > .EAL$page)
+ # if(.ind > main.env$EAL$page)
# EAL$.next <- EAL$.next + 1
# if(.ind < EAL$page)
# EAL$.prev <- EAL$.prev + 1
# })
# })
- # * Helps ====
- observeEvent(input$help, {
- showModal(EAL$help)
- })
})
}
-# * Quit ====
-
-#' @noRd
-#'
-#' @import shiny
-quitButton <- function(id) {
- actionButton(
- NS(id, "quit"),
- "Quit",
- icon = icon("sign-out-alt"),
- width = "100%"
- )
-}
-
-#' @noRd
-#'
-#' @import shiny
-#' @importFrom shinyjs onclick disable enable
-onQuit <- function(id, main.env) {
- moduleServer(id, function(input, output, session) {
- save.variable <- main.env$save.variable
-
- # modal dialog for quitting data description
- quitModal <- modalDialog(
- title = "You are leaving data description.",
- "Are you sure to leave? Some of your metadata have maybe not been saved.",
- easyClose = FALSE,
- footer = tagList(
- actionButton(NS(id, "cancel"), "Cancel"),
- actionButton(NS(id, "save_quit"), "Save & Quit"),
- actionButton(
- NS(id, "simple_quit"),
- "Quit",
- icon("times-circle"),
- class = "redButton"
- )
- )
- )
-
- # quits simply
- observeEvent(input$cancel,
- {
- req(input$quit)
- req(input$cancel)
- removeModal()
- },
- label = "Cancel quit"
- )
-
- # show modal on 'quit' button clicked
- observeEvent(input$quit,
- {
- req(input$quit)
- showModal(quitModal)
- },
- label = "EAL quit?"
- )
-
- # calls saveRDS method and quits
- observeEvent(input$save_quit_button,
- {
- req(input$quit)
- req(input$save_quit_button)
-
- # Save work at this state
- saveReactive(save.variable)
- },
- priority = 1,
- label = "EAL save+quit"
- )
-
- # quits simply
- observeEvent({
- input$simple_quit
- input$save_quit_button
- }, {
- req(input$quit)
- removeModal()
-
- # Clean & reset variables
- main.env$EAL$history <- "SelectDP"
- main.env$EAL$page <- 1
- },
- priority = 0,
- label = "EAL quit",
- ignoreInit = TRUE
- )
- })
-}
-
-# * Save ====
+# * Next ====
#' @noRd
#'
#' @import shiny
-saveButton <- function(id) {
+nextTabButton <- function(id, i) {
actionButton(
- NS(id, "save"),
- "Save",
- icon = icon("save", class = "regular"),
+ NS(id, paste(i, i + 1, sep = "_")),
+ "Next",
+ icon = icon("arrow-right"),
width = "100%"
)
}
-#' @noRd
-#'
-#' @import shiny
-#' @importFrom shinyjs onclick disable enable
-# onSave <- function(id, main.env){
-# moduleServer(id, function(input, output, session) {
-# observeEvent(input$save,
-# {
-# req(input$save)
-# NSB$SAVE <- NSB$SAVE + 1
-# },
-# label = "NSB save"
-# )
-# })
-# }
-
# * Previous ====
#' @noRd
@@ -327,23 +230,9 @@ saveButton <- function(id) {
#' @import shiny
prevTabButton <- function(id, i) {
actionButton(
- NS(id, paste(i, i-1, sep = "_")),
+ NS(id, paste(i, i - 1, sep = "_")),
"Previous",
icon = icon("arrow-left"),
width = "100%"
)
}
-
-# * Next ====
-
-#' @noRd
-#'
-#' @import shiny
-nextTabButton <- function(id, i) {
- actionButton(
- NS(id, paste(i, i+1, sep = "_")),
- "Next",
- icon = icon("arrow-right"),
- width = "100%"
- )
-}
diff --git a/R/header.R b/R/header.R
index 2c13b84..7253e3d 100644
--- a/R/header.R
+++ b/R/header.R
@@ -9,84 +9,91 @@
#'
#' @noRd
.globalScript <- function(
- args = list(
- dev = FALSE,
- wip = FALSE
- )
-) {
-
+ args = list(
+ dev = FALSE,
+ wip = FALSE
+ )) {
+
# Environment setup ====
main.env <- new.env()
-
+
assign("dev", args$dev, main.env)
assign("wip", args$wip, main.env)
-
+
# Paths ====
wwwPaths <- system.file("resources", package = "MetaShARK") %>%
paste(., dir(.), sep = "/") %>%
- as.list
+ as.list()
names(wwwPaths) <- basename(unlist(wwwPaths))
PATHS <- reactiveValues(
home = "~",
eal.dp = paste0("~/dataPackagesOutput/emlAssemblyLine/"),
eal.dp.index = paste0("~/dataPackagesOutput/emlAssemblyLine/index.txt"),
- eal.tmp = paste0("~/EMLAL_tmp/"),
+ eal.tmp = tempdir(),
resources = wwwPaths
)
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")
- }
- else {
- DP.LIST <- data.frame(
- creator.orcid = character(),
- name = character(),
- title = character(),
- path = character(),
- stringsAsFactors = FALSE
- )
- 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)
-
+ # if (isTRUE(file.exists(isolate(PATHS$eal.dp.index)))) {
+ # DP.LIST <- data.table::fread(isolate(PATHS$eal.dp.index), sep = "\t")
+ # }
+ # else {
+ # DP.LIST <- data.frame(
+ # creator.orcid = character(),
+ # name = character(),
+ # title = character(),
+ # path = character(),
+ # stringsAsFactors = FALSE
+ # )
+ # }
+ #
+ # # Curate DP.LIST versus actual list
+ # DP.LIST$path <- DP.LIST$path %>% gsub("//+", "/", .)
+ # .actual.index <- dir(
+ # isolate(main.env$PATHS$eal.dp),
+ # pattern = "_emldp$",
+ # full.names = TRUE
+ # ) %>% gsub("//+", "/", .)
+ # DP.LIST <- dplyr::filter(DP.LIST, path %in% .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 ====
assign(
- "VALUES",
+ "VALUES",
reactiveValues(
thresholds = reactiveValues(
files.size.max = 500000
),
- steps = c("SelectDP", "Data Files", "Attributes", "Categorical Variables",
- "Geographic Coverage", "Taxonomic Coverage", "Personnel", "Miscellaneous",
- "Make EML")
- ),
+ steps = c(
+ "SelectDP",
+ "Data Files",
+ "Attributes",
+ "Categorical Variables",
+ "Geographic Coverage",
+ "Taxonomic Coverage",
+ "Personnel",
+ "Miscellaneous",
+ "Make EML"
+ )
+ ),
envir = main.env
)
-
+
# Formats ====
# DataONE nodes
- .DATAONE.LIST <- try(listFormats(dataone::CNode()))
- if (class(.DATAONE.LIST) == "try-error") {
- .DATAONE.LIST <- data.table::fread(wwwPaths$dataoneCNodesList.txt)
- } else {
- data.table::fwrite(.DATAONE.LIST, wwwPaths$dataoneCNodesList.txt)
- }
-
+ .DATAONE.LIST <- data.table::fread(wwwPaths$dataoneCNodesList.txt)
+
# Taxa authorities
- .TAXA.AUTHORITIES <- try(taxonomyCleanr::view_taxa_authorities())
- if (class(.TAXA.AUTHORITIES) == "try-error") {
- .TAXA.AUTHORITIES <- data.table::fread(wwwPaths$taxaAuthorities.txt)
- } else {
- data.table::fwrite(.TAXA.AUTHORITIES, wwwPaths$taxaAuthorities.txt)
- }
-
+ .TAXA.AUTHORITIES <- data.table::fread(wwwPaths$taxaAuthorities.txt)
+
# Unit types
.all.units <- EML::get_unitList()
.units <- "custom"
@@ -97,9 +104,9 @@
}))
.all.units <- .units
names(.all.units) <- .names
-
+
assign(
- "FORMATS",
+ "FORMATS",
reactiveValues(
dates = c(
"YYYY",
@@ -122,10 +129,10 @@
),
envir = main.env
)
-
+
# Settings ====
assign(
- "SETTINGS",
+ "SETTINGS",
reactiveValues(
logged = FALSE,
user = "public",
@@ -133,28 +140,55 @@
cedar.token = character(),
metacat.token = character(),
metacat.test = FALSE
- ),
+ ),
envir = main.env
)
-
+
# EAL rv ====
assign(
- "EAL",
+ "EAL",
reactiveValues(
page = 1, # page number
- history = character(), # all browsed pages names in steps
- current = character(), # last of history
- completed = FALSE, # is current page completed?
+ history = isolate(main.env$VALUES$steps[1]), # all browsed pages names in steps
+ current = isolate(main.env$VALUES$steps[1]), # last of history
+ completed = FALSE, # is current page completed?
tag.list = tagList(), # side HTML tags to display
help = character(),
.next = 0,
.prev = 0
- ),
+ ),
envir = main.env
)
+
+ assign(
+ "save.variable",
+ initReactive(main.env = main.env),
+ envir = main.env
+ )
+
+ # Local rv ====
+ assign(
+ "local.rv",
+ reactiveValues(),
+ envir = main.env
+ )
- assign("save.variable", initReactive(main.env = main.env), envir = main.env)
-
+ assign(
+ "pageLoad",
+ function(page.invoked, expr) {
+ page.reached <- isolate(main.env$EAL$page)
+ observeEvent(
+ main.env$EAL$page,
+ handlerExpr = c(
+ expression(req(page.reached == page.invoked)),
+ expr
+ ),
+ label = paste("RV loader page", page.invoked)
+ )
+ },
+ envir = main.env
+ )
+
# Patterns ====
assign(
"PATTERNS",
@@ -167,11 +201,11 @@
),
envir = main.env
)
-
+
# output ====
assign("main.env", main.env, .GlobalEnv)
shinyOptions(shiny.reactlog = args$reactlog)
addResourcePath("media", system.file("media/", package = "MetaShARK"))
-
+
return(NULL)
}
diff --git a/R/orcid_connect.R b/R/orcid_connect.R
index f97184a..a0597b7 100644
--- a/R/orcid_connect.R
+++ b/R/orcid_connect.R
@@ -1,20 +1,18 @@
#' @import shiny
orcidUI <- function(id, globals) {
- ns <- NS(id)
-
uiOutput(NS(id, "infos"))
}
#' @import shiny
#' @importFrom shinyjs onclick
-orcid <- function(input, output, session, main.env) {
- ns <- session$ns
-
- # Variable initialization ====
- .SETTINGS <- main.env$SETTINGS
-
- # Set UI ====
- observeEvent(.SETTINGS$logged, {
+orcid <- function(id, main.env) {
+ moduleServer(id, function(input, output, session) {
+
+ # Variable initialization ====
+ .SETTINGS <- main.env$SETTINGS
+
+ # Set UI ====
+ # observeEvent(.SETTINGS$logged, {
output$infos <- renderUI({
if (isFALSE(.SETTINGS$logged)) {
tagList(
@@ -29,93 +27,88 @@ orcid <- function(input, output, session, main.env) {
tagList(
tags$h3("Your name here"),
tags$p("WIP: here will be your infos:"),
- fluidRow(
- column(6,
- tags$p(tags$b("ORCID: "), .SETTINGS$user)
- ),
- column(6)
- ),
+ tags$p(tags$b("ORCID: "), .SETTINGS$user),
actionButton(NS(id, "disconnect"), "Logout", icon = icon("sign-out-alt"))
)
}
})
+ # })
+
+ # Log in/out ====
+ shinyjs::onclick("connect", {
+ if (isTruthy(input$orcid) && grepl(main.env$PATTERNS$ORCID, input$orcid)) {
+ .SETTINGS$logged <- TRUE
+ .SETTINGS$user <- stringr::str_extract(input$orcid, main.env$PATTERNS$ORCID)
+ }
+ else {
+ showNotification(
+ "Invalid or mistyped orcid.",
+ type = "error"
+ )
+ updateTextInput(inputId = "orcid", value = "")
+ }
+ })
+
+ shinyjs::onclick("disconnect", {
+ .SETTINGS$logged <- FALSE
+ .SETTINGS$user <- "public"
+ })
+
+ # TODO check for SNAKE connection
+
+ ###
+ # reso <- httr::GET(
+ # "https://orcid.org/"
+ # )
+ # cookie <- cookies(reso)[cookies(reso)$name == "XSRF-TOKEN", ]
+ # credentials <- list(userId = "000-0003-3416-7653", password = "Z@bud!78")
+ # resa <- httr::POST(
+ # "https://orcid.org/oauth/token",
+ # authenticate(
+ # credentials$userId,
+ # credentials$password
+ # ),
+ # add_headers(c(
+ # accept = "application/json",
+ # `x-xsrf-token` = cookie$value
+ # ))
+ # )
+ ###
+
+ # globals$SESSION$ORCID.TOKEN <- rorcid::orcid_auth(
+ # ORCID.TOKEN <- rorcid::orcid_auth(
+ # reauth = TRUE
+ # )
+ # res <- httr::GET(
+ # "https://cn.dataone.org/portal/oauth?action=start",
+ # add_headers(paste("Authorization: ", ORCID.TOKEN))
+ # # add_headers(paste("Authorization: ", globals$SESSION$ORCID.TOKEN))
+ # )
+ # token <- httr::GET(
+ # "https://cn.dataone.org/portal/token"
+ # )
+ #
+ # orcid <- crul::HttpClient$new(
+ # url = "https://orcid.org/"
+ # )
+ # reso <- orcid$get(
+ # "signin/auth.json"
+ # )
+ # cookie <- curl::handle_cookies(reso$handle) %>%
+ # filter(name == "XSRF-TOKEN")
+ #
+ #
+ # session <- crul::HttpClient$new(
+ # url = "https://cn.dataone.org/",
+ # headers = list(
+ # Authorization = ORCID.TOKEN
+ # )
+ # )
+ # res <- session$get(
+ # "/portal/oauth?action=start"
+ # )
+ # res2 <- session$get(
+ # "/portal/token"
+ # )
})
-
- # Log in/out ====
- shinyjs::onclick("connect", {
- if(isTruthy(input$orcid) && grepl(main.env$PATTERNS$ORCID, input$orcid)){
- .SETTINGS$logged <- TRUE
- .SETTINGS$user <- stringr::str_extract(input$orcid, main.env$PATTERNS$ORCID)
- }
- else {
- showNotification(
- "Invalid or mistyped orcid.",
- type = "error"
- )
- updateTextInput(inputId = "orcid", value = "")
- }
- })
-
- shinyjs::onclick("disconnect", {
- .SETTINGS$logged <- FALSE
- .SETTINGS$user <- "public"
- })
-
- # TODO check for SNAKE connection
-
- ###
- # reso <- httr::GET(
- # "https://orcid.org/"
- # )
- # cookie <- cookies(reso)[cookies(reso)$name == "XSRF-TOKEN", ]
- # credentials <- list(userId = "000-0003-3416-7653", password = "Z@bud!78")
- # resa <- httr::POST(
- # "https://orcid.org/oauth/token",
- # authenticate(
- # credentials$userId,
- # credentials$password
- # ),
- # add_headers(c(
- # accept = "application/json",
- # `x-xsrf-token` = cookie$value
- # ))
- # )
- ###
-
- # globals$SESSION$ORCID.TOKEN <- rorcid::orcid_auth(
- # ORCID.TOKEN <- rorcid::orcid_auth(
- # reauth = TRUE
- # )
- # res <- httr::GET(
- # "https://cn.dataone.org/portal/oauth?action=start",
- # add_headers(paste("Authorization: ", ORCID.TOKEN))
- # # add_headers(paste("Authorization: ", globals$SESSION$ORCID.TOKEN))
- # )
- # token <- httr::GET(
- # "https://cn.dataone.org/portal/token"
- # )
- #
- # orcid <- crul::HttpClient$new(
- # url = "https://orcid.org/"
- # )
- # reso <- orcid$get(
- # "signin/auth.json"
- # )
- # cookie <- curl::handle_cookies(reso$handle) %>%
- # filter(name == "XSRF-TOKEN")
- #
- #
- # session <- crul::HttpClient$new(
- # url = "https://cn.dataone.org/",
- # headers = list(
- # Authorization = ORCID.TOKEN
- # )
- # )
- # res <- session$get(
- # "/portal/oauth?action=start"
- # )
- # res2 <- session$get(
- # "/portal/token"
- # )
-
}
diff --git a/R/runMetashark.R b/R/runMetashark.R
index 2c705c7..5ee0aa8 100644
--- a/R/runMetashark.R
+++ b/R/runMetashark.R
@@ -19,6 +19,8 @@
#' which is designed to help its user as much as possible for filling ecological
#' metadata. It uses the EML standard (cf. NCEAS work) to allow a full and
#' precise description of input datasets.
+#'
+#' For server setup, see [this git](https://github.com/earnaud/MetaShARK_docker).
#'
#' @author
#' Elie Arnaud
@@ -26,17 +28,20 @@
#' @examples
#' # run this to launch MetaShARK
#' runMetashark()
-#'
+#'
#' @export
#' @import shiny
runMetashark <- function(...) {
+ invisible(require("shinyBS"))
+ options(shiny.reactlog = TRUE)
+
args <- list(...)
args$dev <- isTRUE(args$dev)
args$wip <- isTRUE(args$wip)
- args$reactlog <- if(is.null(args$reactlog)) TRUE else isTRUE(args$reactlog)
-
+ args$reactlog <- if (is.null(args$reactlog)) TRUE else isTRUE(args$reactlog)
+
.globalScript(args = args)
- on.exit(rm(main.env, envir=.GlobalEnv))
-
+ on.exit(rm(main.env, envir = .GlobalEnv))
+
runApp(shinyApp(ui = appUI, server = appServer))
}
diff --git a/R/savevariable_functions.R b/R/savevariable_functions.R
index d771a88..9299fcd 100644
--- a/R/savevariable_functions.R
+++ b/R/savevariable_functions.R
@@ -1,24 +1,26 @@
+# Main save variable ====
+
#' @import shiny
-#'
+#'
#' @noRd
initReactive <- function(sub.list = NULL, save.variable = NULL, main.env) {
if (!is.null(sub.list) && is.null(save.variable)) {
- stop("Attempt to initialize save.variable's sub.list without savevar.")
+ stop("Attempt to initialize save.variable's sub.list without save.variable.")
}
if (!(is.null(sub.list) || sub.list %in% c("emlal", "metafin"))) {
stop("Attempt to initialize save.variable with inconsistent arguments")
}
-
+
# re-creates a whole save.variable
if (is.null(sub.list)) {
save.variable <- reactiveValues()
}
-
# emlal reactivelist management
- if (is.null(sub.list) || sub.list == "emlal") {
- save.variable$emlal <- reactiveValues(
- step = isolate(main.env$EAL$page),
+ else if (sub.list == "emlal") {
+ save.variable <- reactiveValues(
+ step = 1,
quick = FALSE,
+ creator = character(),
history = isolate(main.env$EAL$history),
SelectDP = reactiveValues(
dp.name = NULL,
@@ -59,146 +61,85 @@ initReactive <- function(sub.list = NULL, save.variable = NULL, main.env) {
)
)
}
-
# metafin reactivelist management
- if (is.null(sub.list) || sub.list == "metafin") {
- save.variable$metafin <- reactiveValues()
+ else if (sub.list == "metafin") {
+ save.variable <- reactiveValues()
}
-
+
# differential returns
- return(if (is.null(sub.list)) {
- save.variable
- } else {
- switch(sub.list,
- emlal = save.variable$emlal,
- metafin = save.variable$metafin
- )
- })
+ return(save.variable)
}
#' @import shiny
#' @importFrom jsonlite write_json serializeJSON
-#'
+#'
#' @noRd
-saveReactive <- function(
- save.variable,
- rv = NULL,
- write = FALSE
-) {
+saveReactive <- function(main.env) {
+ if(is.null(main.env$local.rv))
+ stop("No content provided.")
+ if(is.null(main.env$save.variable))
+ stop("No save variable provided")
+
withProgress({
setProgress(1 / 3, "Module save")
-
- # Write provided rv
- if (!is.null(rv)) {
- if (is.null(names(rv))) {
- message("No module name! Give it as a name for `rv`.")
- } else {
- rv <- rv[1]
-
- save.variable <- do.call(
- switch(names(rv),
- DataFiles = .saveDataFiles,
- Attributes = .saveAttributes,
- CatVars = .saveCatVars,
- GeoCov = .saveGeoCov,
- TaxCov = .saveTaxCov,
- Personnel = .savePersonnel,
- Misc = .saveMisc,
- ),
- args = list(
- save.variable = savevar,
- rv = rv[[1]],
- write = write
- )
- )
-
- # if (names(rv) == "DataFiles") {
- # save.variable <- .saveDataFiles(
- # save.variable = savevar,
- # rv = rv[[1]]
- # )
- # }
- # if (names(rv) == "Attributes") {
- # save.variable <- .saveAttributes(
- # save.variable = savevar,
- # rv = rv[[1]]
- # )
- # }
- # if (names(rv) == "CatVars") {
- # save.variable <- .saveCatVars(
- # save.variable = savevar,
- # rv = rv[[1]]
- # )
- # }
- # if (names(rv) == "GeoCov") {
- # save.variable <- .saveGeoCov(
- # save.variable = savevar,
- # rv = rv[[1]],
- # main.env = main.env
- # )
- # }
- # if (names(rv) == "TaxCov") {
- # save.variable <- .saveTaxCov(
- # save.variable = savevar,
- # rv = rv[[1]]
- # )
- # }
- # if (names(rv) == "Personnel") {
- # save.variable <- .savePersonnel(
- # save.variable = savevar,
- # rv = rv[[1]]
- # )
- # }
- # if (names(rv) == "Misc") {
- # save.variable <- .saveMisc(
- # save.variable = savevar,
- # rv = rv[[1]]
- # )
- # }
- }
- }
-
+
+ # Write provided content
+ main.env$save.variable <- do.call(
+ switch(main.env$EAL$current,
+ "SelectDP" = .saveSelectDP,
+ "Data Files" = .saveDataFiles,
+ "Attributes" = .saveAttributes,
+ "Categorical Variables" = .saveCatVars,
+ "Geographic Coverage" = .saveGeoCov,
+ "Taxonomic Coverage" = .saveTaxCov,
+ "Personnel" = .savePersonnel,
+ "Miscellaneous" = .saveMisc
+ ),
+ args = list(
+ main.env
+ )
+ )
+
setProgress(2 / 3, "Global save")
-
+
# Save JSON
- path <- save.variable$emlal$SelectDP$dp.path
- filename <- save.variable$emlal$SelectDP$dp.name
+ path <- main.env$save.variable$SelectDP$dp.path
+ filename <- main.env$save.variable$SelectDP$dp.name
location <- paste0(path, "/", filename, ".json")
if (file.exists(location)) {
file.remove(location)
}
jsonlite::write_json(
- jsonlite::serializeJSON(listReactiveValues(save.variable)),
+ jsonlite::serializeJSON(
+ listReactiveValues(main.env$save.variable)
+ ),
location
)
-
+
incProgress(1 / 3)
- }) %>% isolate
-
+ }) %>% isolate()
+
showNotification(
- paste("Saved:", names(rv)[1], "!"),
- duration = 1.5,
+ paste("Saved:", main.env$EAL$current, "."),
+ duration = 1.5,
type = "message"
)
-
- return(save.variable)
}
#' @import shiny
-setSavevar <- function(content, save.variable, lv = 1, root = "root") {
-
+setSaveVariable <- function(content, save.variable, lv = 1, root = "root") {
lapply(
names(content),
function(label) {
sub.content <- content[[label]]
type.content <- typeof(sub.content)
- sub.save.variable <- savevar[[label]]
- type.save.variable <- typeof(sub.savevar)
+ sub.save.variable <- save.variable[[label]]
+ type.save.variable <- typeof(sub.save.variable)
if (is.reactivevalues(sub.save.variable)) {
if (!is.data.frame(sub.content) &&
is.list(sub.content)) {
- x <- setSavevar(content[[label]], save.variable[[label]], lv = lv + 1, root = label)
+ x <- setSaveVariable(content[[label]], save.variable[[label]], lv = lv + 1, root = label)
}
else {
x <- sub.content
@@ -214,4 +155,159 @@ setSavevar <- function(content, save.variable, lv = 1, root = "root") {
)
return(save.variable)
+}
+
+# Local save variable ====
+setLocalRV <- function(main.env){
+
+ browser(expr = main.env$EAL$page == 3)
+
+ main.env$local.rv <- switch(
+ main.env$EAL$current,
+ # SelectDP ----
+ "SelectDP" = reactiveValues(
+ dp.name = character(),
+ dp.title = character(),
+ dp.list = list.files(
+ main.env$PATHS$eal.dp,
+ pattern = "_emldp$",
+ full.names = FALSE
+ ),
+ dp.license = NULL
+ ),
+ # DataFiles ----
+ "Data Files" = reactiveValues(
+ data.files = if (checkTruth(main.env$save.variable$DataFiles)) { # from create button in SelectDP
+ .ind <- which(file.exists(main.env$save.variable$DataFiles$datapath))
+ .col <- which(names(main.env$save.variable$DataFiles) != "metadatapath")
+ main.env$save.variable$DataFiles[.ind, .col]
+ }
+ else
+ data.frame(stringsAsFactors = FALSE)
+ ),
+ # Attributes ----
+ "Attributes" = reactiveValues(
+ current.file = 0,
+ tables = NULL,
+ current.table = NULL,
+ current.preview = NULL,
+ cu.table = data.frame(stringsAsFactors = FALSE),
+ cu.values = rep(NA, 5),
+ modal.on = FALSE,
+ unit.id = character(),
+ units.list = isolate(main.env$FORMATS$units),
+ annotations = reactiveValues(
+ values = data.frame(stringsAsFactors = FALSE),
+ count = 0
+ )
+ ),
+ # CatVars ----
+ "Categorical Variables" = reactiveValues(
+ current.index = 0
+ ),
+ # GeoCov ----
+ "Geographic Coverage" = reactiveValues(
+ columns = reactiveValues(
+ choices = reactiveValues(
+ files = "all",
+ sites = NA_character_,
+ coords = NA_character_
+ ),
+ site = reactiveValues(
+ col = character(),
+ file = character()
+ ),
+ lat = reactiveValues(
+ col = character(),
+ file = character()
+ ),
+ lon = reactiveValues(
+ col = character(),
+ file = character()
+ ),
+ complete = FALSE
+ ),
+ custom = reactiveValues(
+ id = numeric(),
+ coordinates = data.frame(
+ geographicDescription = character(),
+ northBoundingCoordinate = numeric(),
+ southBoundingCoordinate = numeric(),
+ eastBoundingCoordinate = numeric(),
+ westBoundingCoordinate = numeric(),
+ stringsAsFactors = FALSE
+ ),
+ complete = FALSE
+ )
+ ),
+ # TaxCov ----
+ "Taxonomic Coverage" = reactiveValues(
+ taxa.table = character(),
+ taxa.col = character(),
+ taxa.name.type = character(),
+ taxa.authority = character(),
+ complete = FALSE
+ ),
+ # Personnel ----
+ "Personnel" = reactiveValues(
+ Personnel = data.frame(
+ id = numeric(),
+ # Basic Identity
+ givenName = character(),
+ middleInitial = character(),
+ surName = character(),
+ # Contact
+ organizationName = character(),
+ electronicMailAddress = character(),
+ # Personnel information
+ userId = character(),
+ role = character(),
+ # Project information
+ projectTitle = character(),
+ fundingAgency = character(),
+ fundingNumber = character(),
+ stringsAsFactors = FALSE
+ )
+ ),
+ # Misc ----
+ "Miscellaneous" = reactiveValues(
+ # Abstract
+ abstract = reactiveValues(
+ content = character(),
+ file = paste(
+ isolate(main.env$save.variable$SelectDP$dp.metadata.path),
+ "abstract.txt",
+ sep = "/"
+ )
+ ),
+ # Methods
+ methods = reactiveValues(
+ content = character(),
+ file = paste(
+ isolate(main.env$save.variable$SelectDP$dp.metadata.path),
+ "methods.txt",
+ sep = "/"
+ )
+ ),
+ # Keywords
+ keywords = reactiveValues(
+ keyword = kw$keyword,
+ keyword.thesaurus = kw$keyword.thesaurus
+ ),
+ # Temporal coverage
+ temporal.coverage = c(Sys.Date() - 1, Sys.Date()),
+ # Additional information
+ additional.information = reactiveValues(
+ content = character(),
+ file = paste(
+ isolate(main.env$save.variable$SelectDP$dp.metadata.path),
+ "additional_info.txt",
+ sep = "/"
+ )
+ )
+ )
+ # (End) ----
+ )
+
+ return(main.env)
}
\ No newline at end of file
diff --git a/R/server.R b/R/server.R
index 8befb52..7d42007 100644
--- a/R/server.R
+++ b/R/server.R
@@ -4,25 +4,53 @@
#'
#' @noRd
appServer <- function(input, output, session) {
-message("* server")
# get variables
main.env <- get("main.env", .GlobalEnv)
+ assign(
+ "current.tab",
+ reactive(input$side_menu),
+ envir = main.env
+ )
+
if (main.env$dev) {
shinyjs::onclick(
"dev",
{
- browser()
+ if (main.env$current.tab() != "fill") {
+ browser()
+ }
},
asis = TRUE
)
}
+ # Update values ====
+ # DataONE nodes
+ .DATAONE.LIST <- try(dataone::listFormats(dataone::CNode()))
+ if (class(.DATAONE.LIST) != "try-error") {
+ isolate(main.env$dataone.list <- .DATAONE.LIST)
+ data.table::fwrite(
+ .DATAONE.LIST,
+ isolate(main.env$PATHS$resources$dataoneCNodesList.txt)
+ )
+ }
+
+ # Taxa authorities
+ .TAXA.AUTHORITIES <- try(taxonomyCleanr::view_taxa_authorities())
+ if (class(.TAXA.AUTHORITIES) != "try-error") {
+ isolate(main.env$taxa.authorities <- .TAXA.AUTHORITIES)
+ data.table::fwrite(
+ .TAXA.AUTHORITIES,
+ isolate(main.env$PATHS$resources$taxaAuthorities.txt)
+ )
+ }
+
# Head bar server ----
# Options
- observeEvent(input$settings, {
- updateTabItems(session, "side_menu", "settings")
- })
+ # observeEvent(input$settings, {
+ # shinydashboard::updateTabItems(session, "side_menu", "settings")
+ # })
## modules called ----
fill("fill", main.env)
@@ -30,4 +58,8 @@ message("* server")
documentation("documentation")
about("about")
settings("settings", main.env)
+
+ # Hide the loading message when the rest of the server function has executed
+ shinyjs::hide(id = "loading-content", anim = TRUE, animType = "fade")
+ shinyjs::show("app-content")
}
diff --git a/R/settings.R b/R/settings.R
deleted file mode 100644
index 3dfda07..0000000
--- a/R/settings.R
+++ /dev/null
@@ -1,116 +0,0 @@
-#' @title settingsUI
-#'
-#' @description UI part of the settings module. Allow the user to change several settings in the app.
-#'
-#' @import shiny
-settingsUI <- function(id, wip) {
- ns <- NS(id)
-
- tagList(
- tags$h1("Settings"),
- tags$p("This page is dedicated to define different settings in your session."),
-
- # Sessionning ====
- if(isTRUE(wip)){
- fluidRow(
- tags$h2("Login with ORCID"),
- tags$p("Without login, you can write and read all public data packages
- created on this instance of MetaShARK. By logging in, you will be able
- to write private data packages that will not appear on other users list.
- "),
- orcidUI(NS(id, "orcid")),
- # TODO POC ORCID
- class = "inputBox wip"
- )
- },
- # Metacat token input ====
- fluidRow(
- column(
- 8,
- tags$h2("Metacat settings"),
- textAreaInput(NS(id, "metacat_token"),
- "Authentication token",
- width = "120%"
- ),
- checkboxInput(NS(id, "test_metacat"), "Test MetaCat", value = TRUE),
- actionButton(NS(id, "metacat_save"), "Save"),
- if (isTRUE(wip)) {
- textOutput(NS(id, "verbose_token"))
- }
- ),
- column(
- 4,
- tags$b("To fetch your authentication token:"),
- tags$ul(
- tags$li("Login into your metacat through user interface."),
- tags$li("Navigate in the upper-right menu corner and click 'My profile'."),
- tags$li("Click the 'settings' tab and the 'Authentication token' panel."),
- tags$li("Copy paste the authentication token into the dedicated area on the left.")
- )
- ),
- class = "inputBox"
- ),
-
- # CEDAR token input ====
- if(isTRUE(wip))
- {
- fluidRow(
- tags$h2("CEDAR token"),
- column(
- 8,
- textAreaInput(
- NS(id, "cedar_token"),
- "Authentication token",
- width = "120%"
- ),
- actionButton(NS(id, "cedar_save"), "Save")
- ),
- column(
- 4,
- tags$b("To fetch your authentication token:"),
- tags$ul(
- tags$li("Login into your CEDAR profile at: https://cedar.metadatacenter.org/"),
- tags$li("Navigate in the upper-right menu corner and click 'Profile'."),
- tags$li("Paste the content for `key` field before `Usage from REST client`.")
- )
- ),
- class = "inputBox wip"
- )
- }
- )
-}
-
-#' @title settings
-#'
-#' @description server part of the settings module. Allow the user to change several settings in the app.
-#'
-#' @import shiny
-#' @importFrom shinyjs onclick
-#' @importFrom cedarr accessOntology
-settings <- function(id, main.env){
- moduleServer(id, function(input, output, session) {
- # Sessionning ====
- orcid("orcid", main.env)
-
- # Metacat token ====
- observeEvent(input$test_metacat, {
- req(input$test_metacat)
- main.env$SETTINGS$metacat.test <- input$test_metacat
- })
-
- observeEvent(input$metacat_save, {
- main.env$SETTINGS$metacat.token <- input$metacat_token
- showNotification(id = "metacat_set", "Dataone token set.", type = "message")
- })
-
- # CEDAR token ====
- observeEvent({
- input$cedar_token
- input$cedar_save
- }, {
- req(input$cedar_token)
- .SETTINGS$cedar.token <- input$cedar_token
- main.env$SEMANTICS$ontologies <- cedarr::accessOntology(.SETTINGS$cedar.token)
- })
- })
-}
\ No newline at end of file
diff --git a/R/settings_rightSideBar.R b/R/settings_rightSideBar.R
new file mode 100644
index 0000000..1032524
--- /dev/null
+++ b/R/settings_rightSideBar.R
@@ -0,0 +1,164 @@
+#' @title settings in rightSideBar
+#'
+#' @description UI part of the settings module. Allow the user to change several
+#' settings in the app. This is designed to be wrapped in {shinydashboardPlus}.
+#'
+#' @import shiny
+#' @import shinydashboard
+#' @import shinydashboardPlus
+rightSidebarSettings <- function(id, wip) {
+ shinydashboardPlus::rightSidebar(
+
+ # #### MAX 5 PANELS !!!! due to AdminLTE2 ### #
+
+ # Sessionning ====
+ shinydashboardPlus::rightSidebarTabContent(
+ id = 1,
+ title = "Login with ORCID",
+ active = TRUE,
+ icon = "globe",
+ tags$div(
+ if (isTRUE(wip)) {
+ wipRow(
+ collapsibleUI(
+ id = NS(id, "orcid-help"),
+ label = "Interest of ORCID",
+ ... = tags$p(
+ "Without login, you can write and read all", tags$b("public"),
+ "data packages created on this instance of MetaShARK. By logging
+ in, you will be able to write", tags$b("private"), "data packages
+ that will not be visible to other users."
+ )
+ ),
+ orcidUI(NS(id, "orcid"))
+ # TODO POC ORCID
+ )
+ }
+ else {
+ "WIP"
+ }
+ )
+ ),
+
+ # Metacat token input ====
+ shinydashboardPlus::rightSidebarTabContent(
+ id = 2,
+ title = "Metacat settings",
+ icon = "desktop",
+ tags$div(
+ textAreaInput(
+ NS(id, "metacat_token"),
+ "Authentication token"
+ ),
+ tags$span(
+ shinyWidgets::prettySwitch(
+ NS(id, "test_metacat"),
+ "Test MetaCat",
+ value = TRUE
+ ),
+ actionButton(NS(id, "metacat_save"), "Save"),
+ style = "display: inline-block;"
+ ),
+ if (isTRUE(wip)) {
+ textOutput(NS(id, "verbose_token"))
+ } else {
+ NULL
+ },
+ collapsibleUI(
+ NS(id, "help-metacat"),
+ "How to get your token",
+ ... = tagList(
+ tags$b("To fetch your authentication token:"),
+ tags$ul(
+ tags$li("Login into your metacat through user interface."),
+ tags$li("Navigate in the upper-right menu corner and click 'My profile'."),
+ tags$li("Click the 'settings' tab and the 'Authentication token' panel."),
+ tags$li("Copy paste the authentication token into the dedicated area on the left.")
+ )
+ )
+ ),
+ class = "inputBox"
+ )
+ ),
+
+ # CEDAR token input ====
+ shinydashboardPlus::rightSidebarTabContent(
+ id = 3,
+ title = "CEDAR token",
+ icon = "tree",
+ tags$div(
+ if (isTRUE(wip)) {
+ wipRow(
+ textAreaInput(
+ NS(id, "cedar_token"),
+ "Authentication token",
+ width = "120%"
+ ),
+ tags$span(
+ actionButton(NS(id, "cedar_save"), "Save")
+ ),
+ collapsibleUI(
+ NS(id, "help-cedar"),
+ "How to get your token",
+ tagList(
+ tags$b("To fetch your authentication token:"),
+ tags$ul(
+ tags$li("Login into your CEDAR profile at: https://cedar.metadatacenter.org/"),
+ tags$li("Navigate in the upper-right menu corner and click 'Profile'."),
+ tags$li("Paste the content for `key` field before `Usage from REST client`.")
+ )
+ )
+ )
+ ) # end of wipRow
+ }
+ else {
+ "WIP"
+ }
+ )
+ )
+ )
+}
+
+#' @title settings
+#'
+#' @description server part of the settings module. Allow the user to change several settings in the app.
+#'
+#' @import shiny
+#' @importFrom shinyjs onclick
+#' @importFrom cedarr accessOntology
+settings <- function(id, main.env) {
+ moduleServer(id, function(input, output, session) {
+ # Sessionning ====
+ collapsible("help-orcid")
+
+ orcid("orcid", main.env)
+
+ # Metacat token ====
+ collapsible("help-metacat")
+
+ observeEvent(input$test_metacat, {
+ req(input$test_metacat)
+ main.env$SETTINGS$metacat.test <- input$test_metacat
+ })
+
+ observeEvent(input$metacat_save, {
+ main.env$SETTINGS$metacat.token <- input$metacat_token
+ showNotification(id = "metacat_set", "Dataone token set.", type = "message")
+ })
+
+ # CEDAR token ====
+ collapsible("help-cedar")
+
+ observeEvent(
+ {
+ input$cedar_token
+ input$cedar_save
+ },
+ {
+ req(input$cedar_token)
+ .SETTINGS$cedar.token <- input$cedar_token
+ main.env$SEMANTICS$ontologies <- cedarr::accessOntology(.SETTINGS$cedar.token)
+ }
+ )
+ })
+}
diff --git a/R/ui.R b/R/ui.R
index 8292e0f..5609b4f 100644
--- a/R/ui.R
+++ b/R/ui.R
@@ -1,101 +1,167 @@
#' @import shiny
-#' @importFrom shinydashboard dashboardPage dashboardHeader dashboardSidebar
+#' @importFrom shinydashboard dashboardPage dashboardHeader dashboardSidebar
#' sidebarMenu menuItem dashboardBody tabItems tabItem
#' @importFrom shinyjs useShinyjs hidden
-#' @importFrom shinycssloaders withSpinner
#'
#' @noRd
appUI <- function() {
# get app arguments
main.env <- get("main.env", .GlobalEnv)
-
+
# prepare variable
.menu.width <- "250px"
- # ui
- fluidPage(
- includeCSS(system.file("app/www/styles.css", package = "MetaShARK")),
+ tagList(
shinyjs::useShinyjs(),
- # List the first level UI elements here
- shinydashboard::dashboardPage(
- title = "MetaShARK",
- shinydashboard::dashboardHeader(
- tags$li(
- class = "dropdown",
- actionLink("settings", "", icon("gear"))
- ),
- title = tags$img(
- src = "media/ms_logo_small.png",
- width = "200px",
- height = "50px"
- ),
- titleWidth = .menu.width
- ),
- ## Menus ----
- shinydashboard::dashboardSidebar(
- shinydashboard::sidebarMenu(
- id = "side_menu",
- shinydashboard::menuItem("Welcome",
- tabName = "welcome",
- icon = icon("home")
- ),
- shinydashboard::menuItem("Fill in EML",
- tabName = "fill",
- icon = icon("file-import")
- ),
- shinydashboard::menuItem("Upload EML",
- tabName = "upload",
- icon = icon("file-export")
- ),
- shinydashboard::menuItem("EML Documentation",
- tabName = "documentation",
- icon = icon("glasses")
+ shinyjs::inlineCSS("
+ #loading-content {
+ position: absolute;
+ background: #000000;
+ opacity: 0.9;
+ z-index: 100;
+ left: 0;
+ right: 0;
+ height: 100%;
+ text-align: center;
+ color: #FFFFFF;
+ }
+
+ .logo {
+ padding-left: 5px !important;
+ padding-top: 5px !important;
+ }
+ "),
+ # tags$link(
+ # crossorigin="anonymous",
+ # href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css",
+ # integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T",
+ # rel="stylesheet"
+ # ),
+ htmltools::includeCSS(
+ system.file("app/www/styles.css", package = "MetaShARK")
+ ),
+ # Loading message
+ div(
+ id = "loading-content",
+ h2("Loading..."),
+ shinydashboardPlus::loadingState(),
+ tags$img(
+ src = "media/sea_shark.png",
+ width = "50%",
+ height = "25%"
+ )
+ ),
+ shinyjs::hidden(
+ div(
+ id = "app-content",
+ shinydashboardPlus::dashboardPagePlus(
+ title = "MetaShARK",
+ ## Header ====
+ header = shinydashboardPlus::dashboardHeaderPlus(
+ title = tagList(
+ span(
+ class = "logo-lg",
+ tags$img(
+ src = "media/metashark-logo-v4.png",
+ width = "240px",
+ height = "40px"
+ )
+ ),
+ img(
+ src = "media/hex-MetaShARK_squared.png",
+ width = "40px",
+ height = "40px"
+ )
+ ),
+ titleWidth = "250px",
+ enable_rightsidebar = TRUE,
+ rightSidebarIcon = "gears"
),
- shinydashboard::menuItem("About MetaShARK",
- tabName = "about",
- icon = icon("beer")
+ ## Menus ====
+ ## * Tools ----
+ sidebar = shinydashboard::dashboardSidebar(
+ shinydashboard::sidebarMenu(
+ id = "side_menu",
+ shinydashboard::menuItem(
+ "Welcome",
+ tabName = "welcome",
+ icon = icon("home")
+ ),
+ shinydashboard::menuItem(
+ "Fill in EML",
+ tabName = "fill",
+ icon = icon("file-import")
+ ),
+ shinydashboard::menuItem(
+ "Upload EML",
+ tabName = "upload",
+ icon = icon("file-export")
+ ),
+ shinydashboard::menuItem(
+ "EML Documentation",
+ tabName = "documentation",
+ icon = icon("glasses")
+ ),
+ shinydashboard::menuItem(
+ "About MetaShARK",
+ tabName = "about",
+ icon = icon("beer")
+ ),
+ # shinyjs::hidden( # Ghost tab for options
+ # shinydashboard::menuItem(
+ # "settings",
+ # tabName = "settings"
+ # )
+ # ),
+ if (main.env$dev) {
+ tagList(
+ tags$hr(),
+ actionButton(
+ "dev", "DEV CHECK"
+ )
+ )
+ }
+ ),
+ width = "250px"
+ ), # end sidebar
+ # * Settings ----
+ rightsidebar = rightSidebarSettings(
+ "settings",
+ wip = main.env$wip
),
- shinyjs::hidden( # Ghost tab for options
- menuItem("settings",
- tabName = "settings",
- icon = icon("gear")
+ ## Content ====
+ body = shinydashboard::dashboardBody(
+ # tags$script(HTML("$('body').addClass('fixed');")),
+ shinydashboard::tabItems(
+ shinydashboard::tabItem(
+ tabName = "welcome",
+ welcomeUI("welcome", wip = main.env$wip)
+ ),
+ shinydashboard::tabItem(
+ tabName = "fill",
+ fillUI("fill", main.env)
+ ),
+ shinydashboard::tabItem(
+ tabName = "upload",
+ uploadUI("upload", main.env)
+ ),
+ shinydashboard::tabItem(
+ tabName = "documentation",
+ docUI("documentation")
+ ),
+ shinydashboard::tabItem(
+ tabName = "about",
+ aboutUI("about")
+ )
+ # ,
+ # shinydashboard::tabItem(
+ # tabName = "settings",
+ # settingsUI("settings", wip = main.env$wip)
+ # )
)
- ),
- if (isolate(main.env$dev))
- actionButton("dev", "DEV CHECK")
- ),
- width = .menu.width
- ), # end sidebar
- ## Content ----
- shinydashboard::dashboardBody(
- tags$script(HTML("$('body').addClass('fixed');")),
- shinydashboard::tabItems(
- shinydashboard::tabItem(
- tabName = "welcome",
- welcomeUI("welcome", wip=main.env$wip)
- ),
- shinydashboard::tabItem(
- tabName = "fill",
- fillUI("fill", main.env)
- ),
- shinydashboard::tabItem(
- tabName = "upload",
- uploadUI("upload", main.env)
- ),
- shinydashboard::tabItem(
- tabName = "documentation",
- docUI("documentation")
- ),
- shinydashboard::tabItem(
- tabName = "about",
- aboutUI("about")
- ),
- shinydashboard::tabItem(
- tabName = "settings",
- settingsUI("settings", wip=main.env$wip)
- )
- )
- )
- ) # end dashboard
- ) # end fluidPage
+ ) # end body
+ ) # end of dashboardPage
+ ) # end of div
+ ) # end of hidden
+ )
}
diff --git a/R/upload-module.R b/R/upload-module.R
index 493f956..690b109 100644
--- a/R/upload-module.R
+++ b/R/upload-module.R
@@ -10,7 +10,7 @@
uploadUI <- function(id, main.env) {
ns <- NS(id)
dev <- main.env$dev
-
+
registeredEndpoints <- data.table::fread(
isolate(main.env$PATHS$resources)$registeredEndpoints.txt
)
@@ -19,15 +19,16 @@ uploadUI <- function(id, main.env) {
pattern = "_emldp$",
full.names = TRUE
)
- names(dp.list) <- sub("_emldp", "",
+ names(dp.list) <- sub(
+ "_emldp", "",
list.files(
"~/dataPackagesOutput/emlAssemblyLine/",
pattern = "_emldp$"
)
)
-
+
# TODO add update module
-
+
tagList(
tabsetPanel(
id = "upload",
@@ -63,7 +64,7 @@ uploadUI <- function(id, main.env) {
actionButton(NS(id, "toSettings"), "Go to settings", icon("gear")),
class = "leftMargin inputBox"
),
-
+
# files input ----
tags$h3("Select your data package files"),
tags$div(
@@ -72,7 +73,8 @@ uploadUI <- function(id, main.env) {
~/dataPackagesOutput/emlAssemblyLine/ or pick up the files one by one.
Selecting a data package will erase any previous selection."),
fluidRow(
- column(9,
+ column(
+ 9,
# * DP ====
tags$h4("Select a data package"),
selectInput(
@@ -105,21 +107,22 @@ uploadUI <- function(id, main.env) {
),
textOutput(NS(id, "warnings-scripts"))
),
- column(3,
+ column(
+ 3,
tags$h4("Files list"),
uiOutput(NS(id, "filesList"))
)
),
class = "leftMargin inputBox"
),
-
+
# Constraints ----
# div(id="constraints_div",
# tags$h4("Add constraints between script and data files"),
# actionButton(NS(id, "add_constraint"), "", icon = icon("plus"), width = "40px")
# ),
# tags$hr(),
-
+
actionButton(
NS(id, "process"),
"Process",
@@ -130,12 +133,11 @@ uploadUI <- function(id, main.env) {
# Update ----
tabPanel(
title = "update",
- tags$div(
- "WIP",
- # 1. solr query
+ wipRow(
+ "WIP"
+ # 1. solr query
# 2. select items to update
# 3. select files
- class = "inputBox wip"
)
) # end of update tab
) # end of tabSetPanel
@@ -153,44 +155,52 @@ uploadUI <- function(id, main.env) {
#' @importFrom shinyjs enable disable click
#' @importFrom data.table fread fwrite
#' @importFrom mime guess_type
-upload <- function(id, main.env){
+upload <- function(id, main.env) {
moduleServer(id, function(input, output, session) {
-
- registeredEndpoints <- data.table::fread(main.env$PATHS$resources$registeredEndpoints.txt)
+ registeredEndpoints <- data.table::fread(isolate(
+ main.env$PATHS$resources$registeredEndpoints.txt
+ ))
dev <- main.env$dev
-
+
# Select endpoint ----
endpoint <- reactive({
- input$endpoint
+ . <- input$endpoint
})
-
+
memberNode <- reactive({
if (endpoint() != "Other") {
registeredEndpoints %>%
dplyr::filter(mn == endpoint()) %>%
dplyr::select(URL)
} else {
- URL_Input("actual-endpoint")
+ input$other_endpoint
}
})
-
+
output$`actual-endpoint` <- renderUI({
if (endpoint() != "Other") {
tags$p(tags$b("Current endpoint:"), memberNode())
} else {
- URL_Input_UI(NS(id, "actual-endpoint"), "Write the URL of the Member Node")
+ textInput(
+ NS(id, "other_endpoint"),
+ "Write the URL of the Member Node",
+ placeholder = "http://your.server/d1/mn/v2"
+ )
}
})
-
+
# Token input ----
- observeEvent(input$toSettings, {
- shinyjs::click("appOptions", asis = TRUE)
- }, ignoreInit = TRUE)
-
+ observeEvent(input$toSettings,
+ {
+ shinyjs::click("appOptions", asis = TRUE)
+ },
+ ignoreInit = TRUE
+ )
+
observe({
if (!is.character(options("dataone_token")) ||
- !is.character(options("dataone_test_token")) ||
- (is.null(options("dataone_token")) && is.null(options("dataone_test_token")))
+ !is.character(options("dataone_test_token")) ||
+ (is.null(options("dataone_token")) && is.null(options("dataone_test_token")))
) {
output$token_status <- renderUI({
tags$div("UNFILLED", class = "danger")
@@ -204,59 +214,60 @@ upload <- function(id, main.env){
shinyjs::enable("process")
}
})
-
+
# Files input ----
rv <- reactiveValues(
md = data.frame(stringsAsFactors = FALSE),
data = data.frame(stringsAsFactors = FALSE),
scr = data.frame(stringsAsFactors = FALSE)
)
-
- observeEvent(input$DP, {
- .dir <- gsub("/+", "/", input$DP)
- .id <- basename(.dir) %>% sub("_emldp$", "", .)
- .eml.files <- sprintf("%s/%s/eml", .dir, .id) %>%
- dir(full.names = TRUE)
- rv$md <- data.frame(
- name = basename(.eml.files),
- size = base::file.size(.eml.files),
- type = mime::guess_type(.eml.files),
- datapath= .eml.files
- )
-
- .data.files <- sprintf("%s/%s/data_objects", .dir, .id) %>%
- dir(full.names = TRUE)
- rv$data <- data.frame(
- name = basename(.data.files),
- size = base::file.size(.data.files),
- type = mime::guess_type(.data.files),
- datapath = .data.files
- )
- },
+
+ observeEvent(input$DP,
+ {
+ .dir <- gsub("/+", "/", input$DP)
+ .id <- basename(.dir) %>% sub("_emldp$", "", .)
+ .eml.files <- sprintf("%s/%s/eml", .dir, .id) %>%
+ dir(full.names = TRUE)
+ rv$md <- data.frame(
+ name = basename(.eml.files),
+ size = base::file.size(.eml.files),
+ type = mime::guess_type(.eml.files),
+ datapath = .eml.files
+ )
+
+ .data.files <- sprintf("%s/%s/data_objects", .dir, .id) %>%
+ dir(full.names = TRUE)
+ rv$data <- data.frame(
+ name = basename(.data.files),
+ size = base::file.size(.data.files),
+ type = mime::guess_type(.data.files),
+ datapath = .data.files
+ )
+ },
ignoreInit = TRUE,
label = "DPinput"
)
-
- observeEvent(input$metadata,{
+
+ observeEvent(input$metadata, {
rv$md <- input$metadata
showNotification(
"Only one metadata file allowed",
type = "message"
)
})
- observeEvent(input$data,{
+ observeEvent(input$data, {
.add <- input$data
req(checkTruth(.add))
browser() # Update list instead of erasing
rv$data <- rbind(rv$data, .add)
})
- observeEvent(input$scripts,{
+ observeEvent(input$scripts, {
.add <- input$scripts
req(checkTruth(.add))
browser() # Update list instead of erasing
rv$scr <- rbind(input$scripts, .add)
})
-
+
output$filesList <- renderUI({
validate(
need(
@@ -266,48 +277,54 @@ upload <- function(id, main.env){
"No file selected"
)
)
-
+
tagList(
- if(dim(rv$md)[1] > 0)
+ if (dim(rv$md)[1] > 0) {
checkboxGroupInput(
NS(id, "md-files"),
label = "EML file",
choices = rv$md$name
- ),
- if(dim(rv$data)[1] > 0)
+ )
+ },
+ if (dim(rv$data)[1] > 0) {
checkboxGroupInput(
NS(id, "data-files"),
label = "Data files",
choices = rv$data$name
- ),
- if(dim(rv$scr)[1] > 0)
+ )
+ },
+ if (dim(rv$scr)[1] > 0) {
checkboxGroupInput(
NS(id, "scr-files"),
label = "Scripts",
choices = rv$scr$name
- ),
+ )
+ },
actionButton(NS(id, "rmv"), "Remove", class = "danger")
)
})
-
- observeEvent(input$rmv, {
- .rmv <- input$`md-files`
- if(checkTruth(.rmv)){
- .ind <- match(.rmv, rv$md$name)
- rv$md <- rv$md[-.ind,]
- }
- .rmv <- input$`data-files`
- if(checkTruth(.rmv)){
- .ind <- match(.rmv, rv$data$name)
- rv$data <- rv$data[-.ind,]
- }
- .rmv <- input$`scr-files`
- if(checkTruth(.rmv)){
- .ind <- match(.rmv, rv$scr$name)
- rv$scr <- rv$scr[-.ind,]
- }
- }, ignoreInit = TRUE)
-
+
+ observeEvent(input$rmv,
+ {
+ .rmv <- input$`md-files`
+ if (checkTruth(.rmv)) {
+ .ind <- match(.rmv, rv$md$name)
+ rv$md <- rv$md[-.ind, ]
+ }
+ .rmv <- input$`data-files`
+ if (checkTruth(.rmv)) {
+ .ind <- match(.rmv, rv$data$name)
+ rv$data <- rv$data[-.ind, ]
+ }
+ .rmv <- input$`scr-files`
+ if (checkTruth(.rmv)) {
+ .ind <- match(.rmv, rv$scr$name)
+ rv$scr <- rv$scr[-.ind, ]
+ }
+ },
+ ignoreInit = TRUE
+ )
+
observe({
if (
dim(rv$md)[1] != 1 ||
@@ -317,7 +334,7 @@ upload <- function(id, main.env){
} else {
shinyjs::enable("process")
}
-
+
if (
dim(rv$scr)[1] == 0 ||
dim(rv$data)[1] == 0
@@ -327,25 +344,25 @@ upload <- function(id, main.env){
shinyjs::enable("add_constraint")
}
})
-
+
# Process ----
observeEvent(input$process, {
disable("process")
-
+
md.format <- EML::read_eml(as.character(rv$md$datapath))$schemaLocation %>%
strsplit(split = " ") %>%
- unlist %>%
+ unlist() %>%
utils::head(n = 1)
-
+
out <- uploadDP(
mn = registeredEndpoints %>%
dplyr::filter(mn == endpoint()) %>%
dplyr::select(URL) %>%
- as.character,
+ as.character(),
cn = registeredEndpoints %>%
dplyr::filter(mn == endpoint()) %>%
dplyr::select(cn) %>%
- as.character,
+ as.character(),
token = list(
test = main.env$SETTINGS$metacat.test,
prod = main.env$SETTINGS$metacat.token
@@ -369,13 +386,13 @@ upload <- function(id, main.env){
formats = main.env$FORMAT$dataone.list$MediaType,
use.doi = FALSE
)
-
+
if (class(out) == "try-error") {
showNotification(out[1], type = "error")
} else {
showNotification(paste("Uploaded DP", out), type = "message")
}
-
+
shinyjs::enable("process")
})
})
diff --git a/R/upload-module_functions.R b/R/upload-module_functions.R
index fa61ab9..3ea2f56 100644
--- a/R/upload-module_functions.R
+++ b/R/upload-module_functions.R
@@ -17,17 +17,16 @@
#' @importFrom EML read_eml write_eml eml_validate
#' @importFrom mime guess_type
uploadDP <- function(
- # essential
- mn,
- cn,
- token,
- eml,
- data,
- # facultative
- scripts = c(),
- formats,
- use.doi = FALSE
-) {
+ # essential
+ mn,
+ cn,
+ token,
+ eml,
+ data,
+ # facultative
+ scripts = c(),
+ formats,
+ use.doi = FALSE) {
# Set variables ----
message("Init")
@@ -104,7 +103,7 @@ uploadDP <- function(
options(dataone_test_token = token$test)
options(dataone_token = token$prod)
-
+
packageId <- try(
dataone::uploadDataPackage(
d1c,
@@ -115,8 +114,8 @@ uploadDP <- function(
)
)
- if(class(packageId) == "try-error") browser()
-
+ if (class(packageId) == "try-error") browser()
+
options(dataone_test_token = NULL)
options(dataone_token = NULL)
@@ -124,7 +123,7 @@ uploadDP <- function(
}
#' @import shiny
-#'
+#'
#' @noRd
describeWorkflowUI <- function(id, sources, targets) {
ns <- NS(id)
@@ -144,7 +143,7 @@ describeWorkflowUI <- function(id, sources, targets) {
}
#' @import shiny
-#'
+#'
#' @noRd
describeWorkflow <- function(input, output, session) {
ns <- session$ns
diff --git a/R/utils-URL_Input.R b/R/utils-URL_Input.R
index f92be5f..bd35fa9 100644
--- a/R/utils-URL_Input.R
+++ b/R/utils-URL_Input.R
@@ -13,7 +13,7 @@
#' @import shiny
URL_Input_UI <- function(id, label = "URL", width = "100%") {
ns <- NS(id)
-
+
tagList(
textInput(NS(id, "url"), label, placeholder = "https://github.com/earnaud/MetaShARK-v2"),
textOutput(NS(id, "warnings"))
@@ -26,27 +26,27 @@ URL_Input_UI <- function(id, label = "URL", width = "100%") {
#'
#' @import shiny
#' @importFrom RCurl url.exists
-URL_Input <- function(id){
+URL_Input <- function(id) {
moduleServer(id, function(input, output, session) {
# variable initialization
url <- reactiveVal(character())
-
+
# actions
observeEvent(input$url, {
is.url <- RCurl::url.exists(input$url)
-
+
output$warnings <- renderText({
validate(
need(is.url, "Invalid URL target.")
)
return(NULL)
})
-
+
url <- NA_character_
req(is.url)
url <- input$url
})
-
+
return(url)
})
}
diff --git a/R/utils-checkTruth.R b/R/utils-checkTruth.R
index 08842ec..c2fa13f 100644
--- a/R/utils-checkTruth.R
+++ b/R/utils-checkTruth.R
@@ -11,4 +11,4 @@ checkTruth <- function(x) {
stop("'x' is missing with no default.")
}
return(isTruthy(x) && isTruthy(unlist(x)))
-}
\ No newline at end of file
+}
diff --git a/R/utils-collapsible.R b/R/utils-collapsible.R
index ca97a69..a5be06c 100644
--- a/R/utils-collapsible.R
+++ b/R/utils-collapsible.R
@@ -4,17 +4,19 @@
#'
#' @param id character. The input slot that will be used to access the value.
#' @param label character. A label appearing on the clickable link.
-#' @param .hidden logical. A flag to make the UI display as collapsed or not.
+#' @param .hidden logical. A flag to make the UI display as collapsed or not.
#' @param ... shiny UI elements. Any UI element displayed as core content.
#' @param class character. CSS class to apply to ... .
#'
#' @import shiny
#' @importFrom shinyjs useShinyjs hidden
collapsibleUI <- function(id, label, .hidden = TRUE, ..., class = NULL) {
- ns <- NS(id)
-
- content <- tags$div(id = NS(id, "area"), tagList(...), class = class)
-
+ content <- tags$div(
+ id = NS(id, "area"),
+ tagList(...),
+ class = class
+ )
+
tagList(
shinyjs::useShinyjs(),
actionLink(
@@ -34,9 +36,9 @@ collapsibleUI <- function(id, label, .hidden = TRUE, ..., class = NULL) {
#' @import shiny
#' @importFrom shinyjs toggle
-#'
+#'
#' @noRd
-collapsible <- function(id){
+collapsible <- function(id) {
moduleServer(id, function(input, output, session) {
observeEvent(input$link, {
shinyjs::toggle(
@@ -45,14 +47,14 @@ collapsible <- function(id){
animType = "slide",
time = 0.25
)
-
+
if (input$link %% 2 == 1) {
.tmp <- "chevron-down"
} else {
.tmp <- "chevron-right"
}
-
+
updateActionButton(session, "link", icon = icon(.tmp))
})
})
-}
\ No newline at end of file
+}
diff --git a/R/utils-markdownInput.R b/R/utils-markdownInput.R
index 3290e9e..910aa3e 100644
--- a/R/utils-markdownInput.R
+++ b/R/utils-markdownInput.R
@@ -32,8 +32,12 @@ markdownInputUI <- function(id, label = "Text", icon = TRUE, preview = FALSE, va
fluidRow(
column(
if (preview) 6 else 12,
- if (isFALSE(icon)) tags$b(label) else span(tags$b(label), "(", icon("markdown"), "supported)"),
- aceEditor(
+ if (isFALSE(icon)) {
+ tags$b(label)
+ } else {
+ span(tags$b(label), "(", icon("markdown"), "supported)")
+ },
+ shinyAce::aceEditor(
NS(id, "md"),
value = value,
mode = "markdown",
@@ -58,18 +62,18 @@ markdownInputUI <- function(id, label = "Text", icon = TRUE, preview = FALSE, va
#'
#' @import shiny
#' @importFrom markdown markdownToHTML
-markdownInput <- function(id, preview = FALSE){
+markdownInput <- function(id, preview = FALSE) {
moduleServer(id, function(input, output, session) {
rv <- reactive({
input$md
})
-
+
if (preview) {
output$preview <- renderUI({
- HTML(markdownToHTML(file = NULL, text = rv()))
+ HTML(markdown::markdownToHTML(file = NULL, text = rv()))
})
}
-
+
return(rv)
})
}
diff --git a/R/utils-reactiveTrigger.R b/R/utils-reactiveTrigger.R
index a9895e5..a1318ea 100644
--- a/R/utils-reactiveTrigger.R
+++ b/R/utils-reactiveTrigger.R
@@ -5,7 +5,7 @@
#' 1. depend() : must be written in a code chunk to execute on triggering
#' 2. trigger() : when executed, trigger the object (and all the "depending" code chunks)
#' This function is freely reused from Dean Attali's work.
-#'
+#'
#' @import shiny
makeReactiveTrigger <- function() {
rv <- reactiveValues(a = 0)
diff --git a/R/utils-readDataTable.R b/R/utils-readDataTable.R
index c9aed17..f5bd849 100644
--- a/R/utils-readDataTable.R
+++ b/R/utils-readDataTable.R
@@ -13,7 +13,7 @@
#'
#' @importFrom gdata read.xls
readDataTable <- function(file, data.table = FALSE, dev = FALSE, ...) {
- if (missing(file)) {
+ if (missing(file) || length(file) == 0) {
stop("Provide a file for this function.")
}
diff --git a/R/utils-readPlaintext.R b/R/utils-readPlaintext.R
index 090018d..f3a091b 100644
--- a/R/utils-readPlaintext.R
+++ b/R/utils-readPlaintext.R
@@ -8,7 +8,7 @@
#' @importFrom readtext readtext
readPlainText <- function(files, prefix = NULL, sep = "/", ...) {
if (is.null(prefix)) sep <- ""
-
+
readtext::readtext(
paste(
prefix,
@@ -16,4 +16,4 @@ readPlainText <- function(files, prefix = NULL, sep = "/", ...) {
sep = sep
)
)$text
-}
\ No newline at end of file
+}
diff --git a/R/utils-wipRow.R b/R/utils-wipRow.R
new file mode 100644
index 0000000..3de0f2d
--- /dev/null
+++ b/R/utils-wipRow.R
@@ -0,0 +1,7 @@
+wipRow <- function(...) {
+ tags$div(
+ tags$div(style = "height: 10px", class = "topInputRow wip"),
+ ...,
+ class = "inputBox"
+ )
+}
diff --git a/R/utils_withRedStar.R b/R/utils_withRedStar.R
index dd923dd..6e3a33b 100644
--- a/R/utils_withRedStar.R
+++ b/R/utils_withRedStar.R
@@ -11,7 +11,6 @@
#'
#' @examples
#' withRedStar("Enter your name here")
-#'
#' @import shiny
withRedStar <- function(text) {
tags$span(
diff --git a/R/welcome-module.R b/R/welcome-module.R
index 92eedfe..79e261f 100644
--- a/R/welcome-module.R
+++ b/R/welcome-module.R
@@ -3,7 +3,7 @@
#' @description Welcome page of the MetaShARK app.
#'
#' @import shiny
-welcomeUI <- function(id, wip=FALSE) {
+welcomeUI <- function(id, wip = FALSE) {
ns <- NS(id)
fluidPage(
@@ -12,12 +12,11 @@ welcomeUI <- function(id, wip=FALSE) {
# MetaShARK
tags$h1("Welcome in MetaShARK"),
fluidRow(
- if(isTRUE(wip)){
- tags$div(
+ if (isTRUE(wip)) {
+ wipRow(
tags$p("DISCLAIMER: this is a development version. Some parts with
this color code are not meant to be fully functional. So do not
- bother with testing them."),
- class = "inputBox wip"
+ bother with testing them.")
)
},
column(
diff --git a/README.md b/README.md
index f6c84e5..a4bbb38 100644
--- a/README.md
+++ b/README.md
@@ -3,6 +3,11 @@
+**DISCLAIMER: MetaShARK uses temporary files for upload purposes and template
+files for the writing of EML. Thus, installing it in locale will write files on
+dedicated parts of your system (temp dir in HOME and a directory called "dataPackagesOutput"
+in HOME).**
+
**Stable Server address:** http://openstack-192-168-100-47.genouest.org/  `Maintenance`
diff --git a/inst/app/www/styles.css b/inst/app/www/styles.css
index b90d3d6..949a692 100644
--- a/inst/app/www/styles.css
+++ b/inst/app/www/styles.css
@@ -53,8 +53,7 @@ textarea {
.inputBox {
border: 1px solid lightgrey;
border-radius: 10px;
- margin: 5px;
- padding: 0;
+ padding: 5px;
}
.topInputRow {
diff --git a/inst/data-raw/infoBuilder-v2/buildTrees.R b/inst/data-raw/infoBuilder-v2/buildTrees.R
new file mode 100644
index 0000000..d7bfd76
--- /dev/null
+++ b/inst/data-raw/infoBuilder-v2/buildTrees.R
@@ -0,0 +1,57 @@
+rm(list=ls())
+
+library(XML)
+library(dplyr)
+
+# Read files ====
+{
+ xsd.files <- dir("inst/data-raw/xsdFiles/current/", pattern="eml", full.names = TRUE)
+ xsd <- lapply(xsd.files, function(file){
+ xmlParse(file) %>% xmlRoot %>% xmlToList
+ # read_xml(file) %>% as_list %>% .$schema # does not save attributes
+ })
+ names(xsd) <- basename(xsd.files)
+}
+
+# Structure tree ====
+{
+ source("inst/data-raw/infoBuilder-v2/exploreXSD.R")
+
+ nsIndex <- buildNsIndex(xsd.files)
+ doc <- exploreXSD(
+ node = list(
+ self = xsd,
+ name = "root"
+ ),
+ safe = c("annotation", ".attrs"),
+ keep = c(names(xsd), "element", "complexType", "simpleType", "group"),
+ ns = nsIndex
+ )
+ tree <- prettifyTree(doc)
+
+ beepr::beep(5)
+}
+
+# Shiny Tree test ====
+{
+ source("inst/data-raw/infoBuilder-v2/testShinyTree.R")
+
+ renderShinyTree(doc, tree)
+}
+
+# Save to JSON ====
+{
+ library(jsonlite)
+
+ doc.json <- serializeJSON(doc, pretty = TRUE)
+ write_json(doc.json, "./inst/resources/doc_guideline.json")
+ # doc2 <- read_json("inst/data-raw/infoBuilder-v2/doc_guideline.json")[[1]]
+ # doc.back <- unserializeJSON(doc2)
+ # identical(doc, doc.back)
+
+ tree.json <- serializeJSON(tree, pretty = TRUE)
+ write_json(tree.json, "./inst/resources/tree_guideline.json")
+ # tree2 <- read_json("inst/data-raw/infoBuilder-v2/tree_guideline.json")[[1]]
+ # tree.back <- unserializeJSON(tree2)
+ # identical(tree, tree.back)
+}
diff --git a/inst/data-raw/infoBuilder-v2/testShinyTree.R b/inst/data-raw/infoBuilder-v2/testShinyTree.R
index f2d8816..d3889bd 100644
--- a/inst/data-raw/infoBuilder-v2/testShinyTree.R
+++ b/inst/data-raw/infoBuilder-v2/testShinyTree.R
@@ -42,32 +42,27 @@ testShinyTree_UI <- function(id) {
)
}
-testShinyTree <- function(input, output, session, doc, tree) {
- output$tree <- renderTree({
- tree
- })
-
- # output$selected <- renderPrint({
- # browser()
- # tree <- input$tree
- # req(tree)
- # get_selected(tree)
- # })
-
- output$doc <- renderUI({
- tree.node <- get_selected(input$tree)
- validate(
- need(unlist(tree.node), "(Select an item first)")
- )
- path <- paste(c(attr(tree.node[[1]], "ancestry"), unlist(tree.node)), collapse = "/")
- doc.node <- followPath(doc, path)
- if("annotation" %in% names(doc.node))
- doc.node$annotation
- else
- helpText("No content found at:", path)
- })
-
- observeEvent(input$browse, {
- browser()
+testShinyTree <- function(id, doc, tree) {
+ moduleServer(id, function(input, output, session){
+ output$tree <- renderTree({
+ tree
+ })
+
+ output$doc <- renderUI({
+ tree.node <- get_selected(input$tree)
+ validate(
+ need(unlist(tree.node), "(Select an item first)")
+ )
+ path <- paste(c(attr(tree.node[[1]], "ancestry"), unlist(tree.node)), collapse = "/")
+ doc.node <- followPath(doc, path)
+ if("annotation" %in% names(doc.node))
+ doc.node$annotation
+ else
+ helpText("No content found at:", path)
+ })
+
+ observeEvent(input$browse, {
+ browser()
+ })
})
}
diff --git a/inst/media/.canva_logo.png.svg b/inst/media/.canva_logo.png.svg
new file mode 100644
index 0000000..7123081
--- /dev/null
+++ b/inst/media/.canva_logo.png.svg
@@ -0,0 +1,497 @@
+
+
+
+
+
+
+
+ image/svg+xml
+
+
+
+
+
+
+
+ MetaShARK
+
+
+ MetaShARK
+
+
+
+
+
+ MetaShARK
+
+ MetaShARK
+
+
+
diff --git a/inst/media/hex-MetaShARK_squared.png b/inst/media/hex-MetaShARK_squared.png
new file mode 100644
index 0000000..47b6f2d
Binary files /dev/null and b/inst/media/hex-MetaShARK_squared.png differ
diff --git a/inst/media/metashark-logo-v4.png b/inst/media/metashark-logo-v4.png
new file mode 100644
index 0000000..b5773c9
Binary files /dev/null and b/inst/media/metashark-logo-v4.png differ
diff --git a/inst/media/sea_shark.png b/inst/media/sea_shark.png
new file mode 100644
index 0000000..5100e24
Binary files /dev/null and b/inst/media/sea_shark.png differ
diff --git a/inst/media/white_shark.png b/inst/media/white_shark.png
new file mode 100644
index 0000000..bdfc5af
Binary files /dev/null and b/inst/media/white_shark.png differ
diff --git a/man/rightSidebarSettings.Rd b/man/rightSidebarSettings.Rd
new file mode 100644
index 0000000..3557f2d
--- /dev/null
+++ b/man/rightSidebarSettings.Rd
@@ -0,0 +1,12 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/settings_rightSideBar.R
+\name{rightSidebarSettings}
+\alias{rightSidebarSettings}
+\title{settings in rightSideBar}
+\usage{
+rightSidebarSettings(id, wip)
+}
+\description{
+UI part of the settings module. Allow the user to change several
+settings in the app. This is designed to be wrapped in {shinydashboardPlus}.
+}
diff --git a/man/runMetashark.Rd b/man/runMetashark.Rd
index d36027e..6607ad0 100644
--- a/man/runMetashark.Rd
+++ b/man/runMetashark.Rd
@@ -22,6 +22,8 @@ MetaShARK (METAdata SHiny Automated Resource & Knowledge) is a web app
which is designed to help its user as much as possible for filling ecological
metadata. It uses the EML standard (cf. NCEAS work) to allow a full and
precise description of input datasets.
+
+For server setup, see [this git](https://github.com/earnaud/MetaShARK_docker).
}
\examples{
# run this to launch MetaShARK
diff --git a/man/settings.Rd b/man/settings.Rd
index 12efeac..f31dba4 100644
--- a/man/settings.Rd
+++ b/man/settings.Rd
@@ -1,5 +1,5 @@
% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/settings.R
+% Please edit documentation in R/settings_rightSideBar.R
\name{settings}
\alias{settings}
\title{settings}
diff --git a/man/settingsUI.Rd b/man/settingsUI.Rd
deleted file mode 100644
index 5841f8c..0000000
--- a/man/settingsUI.Rd
+++ /dev/null
@@ -1,11 +0,0 @@
-% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/settings.R
-\name{settingsUI}
-\alias{settingsUI}
-\title{settingsUI}
-\usage{
-settingsUI(id, wip)
-}
-\description{
-UI part of the settings module. Allow the user to change several settings in the app.
-}
diff --git a/man/withRedStar.Rd b/man/withRedStar.Rd
index 7188c4e..4f40657 100644
--- a/man/withRedStar.Rd
+++ b/man/withRedStar.Rd
@@ -20,5 +20,4 @@ Adds a red star at the end of the text
}
\examples{
withRedStar("Enter your name here")
-
}