Skip to content

Commit

Permalink
removed print statements
Browse files Browse the repository at this point in the history
  • Loading branch information
triphook committed Feb 12, 2024
1 parent 9e47ac9 commit 2ed5af6
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 21 deletions.
1 change: 1 addition & 0 deletions R/app_server.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# Below increases the max data upload size from the Shiny default of 5MB per file
# to 30MB for file
options(shiny.maxRequestSize = 30 * 1024^2)
options(warn = 2)
app_server <- function(input, output, session) {
# Your application server logic
tadat <- shiny::reactiveValues() # create a list object that holds reactive values passed between modules
Expand Down
12 changes: 6 additions & 6 deletions R/mod_data_flagging.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,14 @@ mod_data_flagging_server <- function(id, tadat) {
# Runs whenever selected flags are changed
shiny::observeEvent(tadat$selected_flags, {
if (!is.null(tadat$removals)) {
tadat$removals = dplyr::select(tadat$removals, -(dplyr::starts_with(flag_prefix)))
tadat$removals = dplyr::select(tadat$removals,-(dplyr::starts_with(flag_prefix)))
}
# Loop through the flags
for (flag in tadat$selected_flags) {
# If not all the values are NA, add the test results to removals
if (!is.null(tadat$removals)) {
if (!all(is.na(values$testResults[flag]))) {
# Problem here?
tadat$removals[paste0(flag_prefix, flag)] = values$testResults[flag]
}
}
Expand Down Expand Up @@ -124,7 +125,6 @@ mod_data_flagging_server <- function(id, tadat) {

shiny::observeEvent(tadat$flags_present, {
if (tadat$flags_present) {

# A table (raw rows, flags) indicating whether each record passes each test
values$testResults <- flagCensus(tadat$raw)

Expand Down Expand Up @@ -193,7 +193,7 @@ mod_data_flagging_server <- function(id, tadat) {
# Add flagging columns to raw table, make sure line below is
# not commented out once done with testing
tadat$raw <- applyFlags(tadat$raw, tadat$orgs)

#write.csv(tadat$raw, "flagged.csv")
#tadat$raw = utils::read.csv("flagged.csv") # THIS IS TRIPS WORKING FILE FOR TESTING, COMMENT OUT WHEN COMMITTING TO DEVELOP

Expand Down Expand Up @@ -226,11 +226,11 @@ mod_data_flagging_server <- function(id, tadat) {
text = "Converting depth units to inches...",
session = shiny::getDefaultReactiveDomain()
)

tadat$raw <-
TADA::TADA_ConvertDepthUnits(tadat$raw, unit = "in")

}
}
if (input$m2f == "meters") {
shinybusy::show_modal_spinner(
spin = "double-bounce",
Expand Down
15 changes: 15 additions & 0 deletions R/mod_filtering.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
mod_filtering_ui <- function(id) {
ns <- NS(id)
tagList(
shiny::fluidRow(column(
6,
shiny::radioButtons(
ns("field_sel"),
label = "",
choices = c("key", "most", "all"),
selected = "key",
inline = TRUE
)
)),
htmltools::HTML("<h3>Select field to filter on:</h3>"),
htmltools::HTML(
"Key columns are listed in the table below, along with the number of unique values present in that field. These counts do not include unique values from results flagged for removal. Click on a field name and a new table will appear below showing the counts associated with each unique value in the selected field."
Expand Down Expand Up @@ -169,6 +179,11 @@ mod_filtering_server <- function(id, tadat) {
}
})


shiny::observeEvent(tadat$field_sel, {
shiny::updateRadioButtons(session, "field_sel", selected = tadat$field_sel)
})

# reset all filters in bottom table
shiny::observeEvent(input$resetFilters, {
# empty selected table on open
Expand Down
31 changes: 16 additions & 15 deletions R/utils_flag_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ test_table <- utils::read.csv("inst/flag_tests.csv")
# test_table = utils::read.csv(app_sys("flag_tests.csv"))
prompt_table <- prompt_table[order(prompt_table$Order),]
prompts <- prompt_table$Prompt
# As of 1/10/2024, this isn't being generated by the flagging process
missing_flags = list("TADA.SingleOrgDup.Flag")
active_flags = setdiff(unique(merge(prompt_table, test_table)$columnName), missing_flags)
active_flags = unique(merge(prompt_table, test_table)$columnName)
levs <- prompt_table$Level
n_switches <- length(prompts)
flag_types <- prompt_table$flagType
Expand Down Expand Up @@ -79,32 +77,33 @@ getCounts <- function(sites, removed_records) {
}
# Settings for each flag function in flag page mock up
applyFlags <- function(in_table, orgs) {
out <- TADA::TADA_IDCensoredData(in_table)
# Invalid Speciation
out <- TADA::TADA_FlagSpeciation(in_table, clean = "none")
out <- TADA::TADA_FlagSpeciation(out, clean = "none")

# Invalid fraction
out <- TADA::TADA_FlagFraction(out, clean = FALSE)

# Invalid result unit
out <- TADA::TADA_FlagResultUnit(out, clean = "none")

print(paste0("Step 5: ", nrow(out)))
# QC rep/blank
out <- TADA::TADA_FindQCActivities(out, clean = FALSE)

# Result is flagged as suspect by data submitter
out <- TADA::TADA_FlagMeasureQualifierCode(out, clean = FALSE, define = TRUE)

# Invalid analytical method
out <- TADA::TADA_FlagMethod(out, clean = FALSE)

# Single org duplicative uploads
out <- TADA::TADA_FindPotentialDuplicatesSingleOrg(out)

# multiple org duplicative uploads
## NOTE: THIS FUNCTION USES A REACTIVE OBJECT AS AN INPUT
out <-
TADA::TADA_FindPotentialDuplicatesMultipleOrgs(out, org_hierarchy = orgs)

# QAPP Not Approved - this flag isn't looking for a TADA-created flag column,
# so do not need to run any flag function here. If switched ON, remove all data
# with QAPPApproved == N or NA.
Expand All @@ -119,10 +118,10 @@ applyFlags <- function(in_table, orgs) {

# Aggregated continuous data
out <- TADA::TADA_FindContinuousData(out, clean = FALSE)

# Above WQX Upper Threshold
out <- TADA::TADA_FlagAboveThreshold(out, clean = FALSE)

# Below WQX Lower Threshold
out <- TADA::TADA_FlagBelowThreshold(out, clean = FALSE)

Expand All @@ -141,11 +140,13 @@ applyFlags <- function(in_table, orgs) {
checkFlagColumns <- function(dataset) {
missing <- setdiff(active_flags, names(dataset))
found = setdiff(active_flags, missing)
print(missing)
print(found)
if (length(missing) > length(found)) {
return(FALSE)
} else {
if (length(missing) > 0){
print("Missing the following fields that are in the csv files:")
print(missing)
}
return(TRUE)
}
}

0 comments on commit 2ed5af6

Please sign in to comment.