Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manage input on censor tab #158 #191

Merged
merged 6 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion R/mod_TADA_summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ mod_TADA_summary_server <- function(id, tadat) {
shiny::req(tadat$raw)
shiny::downloadButton(ns("download_working"),
"Download Working Dataset (.zip)",
style = "color: #fff; background-color: #337ab7; border-color: #2e6da4",
style = "color: #fff; background-color: #337ab7; border-color: #2e6da4; margin-bottom: 10px;",
contentType = "application/zip"
)
})
Expand Down
56 changes: 50 additions & 6 deletions R/mod_censored_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ mod_censored_data_ui <- function(id) {
shiny::fluidRow(
column(
3,
shiny::actionButton(ns("apply_methods"), "Apply Methods to Dataset", style = "color: #fff; background-color: #337ab7; border-color: #2e6da4")
shiny::actionButton(
ns("apply_methods"),
"Apply Methods to Dataset",
disabled = TRUE,
style = "color: #fff; background-color: #337ab7; border-color: #2e6da4")
),
column(3, shiny::uiOutput(ns("undo_methods")))
),
Expand Down Expand Up @@ -99,7 +103,7 @@ mod_censored_data_ui <- function(id) {
mod_censored_data_server <- function(id, tadat) {
shiny::moduleServer(id, function(input, output, session) {
ns <- session$ns

# initialize dropdown values

# reactive values specific to this module
Expand Down Expand Up @@ -162,9 +166,9 @@ mod_censored_data_server <- function(id, tadat) {
if (is.null(init_val)) {
init_val <- 0.5
}
if (input$nd_method == nd_method_options[1]) {
if (input$nd_method == "Multiply detection limit by x") {
shiny::numericInput(ns("nd_mult"),
"Multiplier (x)",
"Non-Detect Multiplier (x)",
value = init_val,
min = 0
)
Expand All @@ -177,9 +181,9 @@ mod_censored_data_server <- function(id, tadat) {
if (is.null(init_val)) {
init_val <- 0.5
}
if (input$od_method == od_method_options[1]) {
if (input$od_method == "Multiply detection limit by x") {
shiny::numericInput(ns("od_mult"),
"Multiplier (x)",
"Over-Detect Multiplier (x)",
value = init_val,
min = 0
)
Expand Down Expand Up @@ -211,18 +215,44 @@ mod_censored_data_server <- function(id, tadat) {
# Make this part more concise?
shiny::observeEvent(input$nd_method, {
tadat$nd_method <- input$nd_method

if ((input$nd_method == "Multiply detection limit by x" && !is.numeric(input$nd_mult))
|| (input$nd_method == "No change" && input$od_method == "No change" )){
shinyjs::disable("apply_methods")
} else {
shinyjs::enable("apply_methods")
}
})

shiny::observeEvent(input$nd_mult, {
tadat$nd_mult <- input$nd_mult

if (input$nd_method == "Multiply detection limit by x" && !is.numeric(input$nd_mult)) {
shinyjs::disable("apply_methods")
} else {
shinyjs::enable("apply_methods")
}
})

shiny::observeEvent(input$od_method, {
tadat$od_method <- input$od_method

if ((input$od_method == "Multiply detection limit by x" && !is.numeric(input$od_mult))
|| (input$nd_method == "No change" && input$od_method == "No change" )){
shinyjs::disable("apply_methods")
} else {
shinyjs::enable("apply_methods")
}
})

shiny::observeEvent(input$od_mult, {
tadat$od_mult <- input$od_mult

if (input$od_method == "Multiply detection limit by x" && !is.numeric(input$od_mult)) {
shinyjs::disable("apply_methods")
} else {
shinyjs::enable("apply_methods")
}
})


Expand Down Expand Up @@ -292,6 +322,13 @@ mod_censored_data_server <- function(id, tadat) {
dat[1:10, ] # just show the first 10 records so user can see what happened to data
shinybusy::remove_modal_spinner(session = shiny::getDefaultReactiveDomain())
tadat$censor_applied <- TRUE

# disable the button so the user can not redo the handling
shinyjs::disable("apply_methods")
shinyjs::disable("nd_mult")
shinyjs::disable("nd_method")
shinyjs::disable("od_mult")
shinyjs::disable("od_method")
})

# this button appears after someone has applied the OD/ND methods, in case they want to undo and try another method instead
Expand All @@ -313,6 +350,13 @@ mod_censored_data_server <- function(id, tadat) {
"Result Value/Unit Copied from Detection Limit" # reset data types flag to what it was before simpleCensoredMethods function run
tadat$raw <- tadat$raw %>% dplyr::select(-TADA.CensoredMethod)
tadat$censor_applied <- FALSE

# enable the button so the user can re-apply the handling
shinyjs::enable("apply_methods")
shinyjs::enable("nd_mult")
shinyjs::enable("nd_method")
shinyjs::enable("od_mult")
shinyjs::enable("od_method")
})

# creates a nice table showing an example of how censored data were changed.
Expand Down
10 changes: 9 additions & 1 deletion R/mod_query_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ mod_query_data_ui <- function(id) {
ns("example_data_go"),
"Load",
shiny::icon("truck-ramp-box"),
disabled = TRUE,
style = "color: #fff; background-color: #337ab7; border-color: #2e6da4"
)
)),
Expand Down Expand Up @@ -255,6 +256,13 @@ mod_query_data_server <- function(id, tadat) {
shiny::moduleServer(id, function(input, output, session) {
ns <- session$ns

# https://stackoverflow.com/questions/24175997/force-no-default-selection-in-selectinput
shiny::observeEvent(input$example_data, {
if (!is.na(input$example_data) && nchar(input$example_data) > 1) {
shinyjs::enable("example_data_go")
}
})

# read in the excel spreadsheet dataset if this input reactive object is populated via fileInput and define as tadat$raw
shiny::observeEvent(input$file, {
# a modal that pops up showing it's working on querying the portal
Expand Down Expand Up @@ -409,7 +417,7 @@ mod_query_data_server <- function(id, tadat) {
if (input$huc == "") {
tadat$huc <- "null"
} else {
tadat$huc <- input$huc
tadat$huc <- gsub("\\s", "", input$huc)
}
if (is.null(input$siteid)) {
tadat$siteid <- "null"
Expand Down
Loading