Skip to content

Commit

Permalink
Refactoring earnaud#5
Browse files Browse the repository at this point in the history
  • Loading branch information
earnaud committed Jul 16, 2020
1 parent 0e2fedb commit 9ad7f13
Show file tree
Hide file tree
Showing 19 changed files with 564 additions and 561 deletions.
Binary file modified .RData
Binary file not shown.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Imports:
Remotes:
ThinkR-open/tagsinput,
ropenscilabs/emldown
RoxygenNote: 7.1.0
RoxygenNote: 7.1.1
URL: https://github.com/earnaud/MetaShARK-v2.git
BugReports: https://github.com/earnaud/MetaShARK-v2.git/issues
Suggests:
Expand Down
20 changes: 9 additions & 11 deletions R/eal_2_DataFiles.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
#'
#' @noRd
DataFilesUI <- function(id, main.env) {
ns <- NS(id)

return(
fluidPage(
tags$b("Disclaimers:"),
Expand Down Expand Up @@ -147,7 +145,7 @@ DataFiles <- function(id, main.env) {
df$name,
function(label) {
# Variable initialization
id <- match(label, df$name)
.id <- match(label, df$name)
xls.warning <- if (grepl("xlsx?$", label)) {
tags$div(
"Only the first sheet of Excel files will be read.",
Expand All @@ -159,7 +157,7 @@ DataFiles <- function(id, main.env) {

# Output
collapsibleUI(
id = ns(id),
id = NS(id, .id),
label = label,
hidden = FALSE,
class = "inputBox",
Expand All @@ -168,15 +166,15 @@ DataFiles <- function(id, main.env) {
column(
6,
textInput(
ns(paste0(id, "-dataName")),
NS(id, paste0(.id, "-dataName")),
"Data table name",
value = label
)
),
column(
6,
URL_Input_UI(
ns(paste0(id, "-dataURL")),
NS(id, paste0(.id, "-dataURL")),
label = "Data remote location"
)
),
Expand All @@ -186,7 +184,7 @@ DataFiles <- function(id, main.env) {
column(
12,
textAreaInput(
ns(paste0(id, "-dataDesc")),
NS(id, paste0(.id, "-dataDesc")),
"Data Table Description",
value = paste("Content of", label),
width = "100%"
Expand All @@ -209,9 +207,9 @@ DataFiles <- function(id, main.env) {
any(grepl("dataURL", names(input))) ||
any(grepl("dataDesc", names(input)))
)
sapply(rv$data.files$name, function(id) {
collapsible(id)
ind <- match(id, rv$data.files$name)
sapply(rv$data.files$name, function(.id) {
collapsible(.id)
ind <- match(.id, rv$data.files$name)

# Data name
observeEvent(input[[paste0(ind, "-dataName")]],
Expand Down Expand Up @@ -266,7 +264,7 @@ DataFiles <- function(id, main.env) {
tags$p(
utils::object.size(files.size),
if (files.size >= files.size.max) {
paste("Max. recommended:", utils::object.size(files.size.max))
paste("Max. recommended:", utils:::format.object_size(files.size.max))
} else {
NULL
},
Expand Down
6 changes: 3 additions & 3 deletions R/eal_3_Attributes.R
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ Attributes <- function(id, main.env) {

# GUI
attributeInputUI(
ns(inputId),
NS(id, inputId),
colname,
saved.value,
main.env$FORMATS,
Expand All @@ -311,7 +311,7 @@ Attributes <- function(id, main.env) {
# Preview ====
h4("Preview:"),
tableOutput(
ns(paste0(
NS(id, paste0(
"preview-",
colnames(rv$current.preview)[row.index]
))
Expand All @@ -320,7 +320,7 @@ Attributes <- function(id, main.env) {
# Annotate ====
# tags$div(
# annotateUI(
# ns(paste(
# NS(id, paste(
# "annotate",
# isolate(rv$current.file),
# row.index,
Expand Down
168 changes: 84 additions & 84 deletions R/eal_3_attributeInput.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ attributeInputUI <- function(id, colname, value, formats, rv) {

ui <- switch(colname,
attributeDefinition = textAreaInput(
ns(colname),
NS(id, colname),
value = value,
withRedStar("Describe the attribute")
),
class = selectInput(
ns(colname),
NS(id, colname),
"Dectected class (change if misdetected)",
choices = c("numeric", "character", "Date", "categorical"),
selected = value
),
unit = {
tmp <- selectInput(
ns(colname),
NS(id, colname),
withRedStar("Select an unit"),
rv$units.list,
selected = if (isTruthy(value)) value
Expand All @@ -29,7 +29,7 @@ attributeInputUI <- function(id, colname, value, formats, rv) {
},
dateTimeFormatString = {
tmp <- selectInput( # TODO better hour format
ns(colname),
NS(id, colname),
withRedStar("Select a date format"),
unique(c(value, formats$DATE)),
selected = value
Expand All @@ -41,12 +41,12 @@ attributeInputUI <- function(id, colname, value, formats, rv) {
}
},
missingValueCode = textInput(
ns(colname),
NS(id, colname),
"Code for missing value (max 1 word)",
value = value
),
missingValueCodeExplanation = textAreaInput(
ns(colname),
NS(id, colname),
"Explain Missing Values",
value = value
),
Expand All @@ -58,88 +58,88 @@ attributeInputUI <- function(id, colname, value, formats, rv) {

#' @import shiny
#' @importFrom shinyjs show hide
attributeInput <- function(input, output, session,
rv, row.index, colname, obs, curt) {
ns <- session$ns

obs[[ns(colname)]] <- observeEvent(input[[colname]],
{
req(input[[colname]])

.val <- input[[colname]]

# Class ====
if (colname == "class") {
# Date
date.id <- "dateTimeFormatString"
if (input[[colname]] == "Date") {
isolate(rv$current.table[row.index, "unit"] <- input[[date.id]])
shinyjs::show(date.id)
} else {
isolate(rv$current.table[row.index, "dateTimeFormatString"] <- "")
shinyjs::hide(date.id)
}
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]])

# Unit
unit.id <- "unit"
if (input[[colname]] == "numeric") {
isolate(rv$current.table[row.index, "unit"] <- input[[unit.id]])
shinyjs::show(unit.id)
} else {
isolate(rv$current.table[row.index, "unit"] <- "")
shinyjs::hide(unit.id)
}
}
# Missing Value Code ====
if (colname == "missingValueCode") { # input: missing Value code
if (grepl(".+ +.*", input[[colname]])) {
.val <- strsplit(gsub("^ +", "", .val), split = " ")[[1]][1]
.val <- input[[colname]]

# Class ====
if (colname == "class") {
# Date
date.id <- "dateTimeFormatString"
if (input[[colname]] == "Date") {
isolate(rv$current.table[row.index, "unit"] <- input[[date.id]])
shinyjs::show(date.id)
} else {
isolate(rv$current.table[row.index, "dateTimeFormatString"] <- "")
shinyjs::hide(date.id)
}

updateTextInput(
session,
colname,
value = .val
)
showNotification(
id = session$NS(id, "mvc_update"),
ui = HTML("<code>missingValueCode</code> fields are limited to a
<b>single word.</b>"),
duration = 3,
type = "warning"
)
# Unit
unit.id <- "unit"
if (input[[colname]] == "numeric") {
isolate(rv$current.table[row.index, "unit"] <- input[[unit.id]])
shinyjs::show(unit.id)
} else {
isolate(rv$current.table[row.index, "unit"] <- "")
shinyjs::hide(unit.id)
}
}
}
# Units ====
if (grepl("unit", ns(colname))) {
# Trigger CU
if (input[[colname]] == "custom" &&
isFALSE(rv$modal.on)) {
curt$trigger()
# Missing Value Code ====
if (colname == "missingValueCode") { # input: missing Value code
if (grepl(".+ +.*", input[[colname]])) {
.val <- strsplit(gsub("^ +", "", .val), split = " ")[[1]][1]

updateTextInput(
session,
colname,
value = .val
)
showNotification(
id = session$NS(id, "mvc_update"),
ui = HTML("<code>missingValueCode</code> fields are limited to a
<b>single word.</b>"),
duration = 3,
type = "warning"
)
}
}

if (isFALSE(input[[colname]] %in% rv$units.list)) {
.cu <- rv$current.table[row.index, colname]
if (.cu %in% rv$cu.table$id) {
.ind <- which(rv$cu.table$id == .cu)
rv$cu.table$id <- rv$cu.table$id[-.ind]
# Units ====
if (grepl("unit", NS(id, colname))) {
# Trigger CU
if (input[[colname]] == "custom" &&
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) {
.ind <- which(rv$cu.table$id == .cu)
rv$cu.table$id <- rv$cu.table$id[-.ind]
}
}
}
}

# Set values ====
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(colname)
)

# Output ----
return(obs)
# Set values ====
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)
})
}
3 changes: 1 addition & 2 deletions R/eal_4_CatVars.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ CatVarsUI <- function(id, main.env) {
CatVars <- function(id, main.env) {
moduleServer(id, function(input, output, session){
save.variable <- main.env$save.variable
ns <- session$ns

# variables initialization ----
rv <- reactiveValues(
Expand Down Expand Up @@ -113,7 +112,7 @@ CatVars <- function(id, main.env) {
)

textAreaInput(
ns(input.id),
NS(id, input.id),
cod,
value = rv[[file.name]]$CatVars %>%
dplyr::filter(attributeName == attribute, code == cod) %>%
Expand Down
Loading

0 comments on commit 9ad7f13

Please sign in to comment.