From 302902810344ffcef4a7fb52a6659b8c8451ad2b Mon Sep 17 00:00:00 2001 From: nfrerebeau <33983845+nfrerebeau@users.noreply.github.com> Date: Sun, 10 Nov 2019 18:28:30 +0100 Subject: [PATCH] Display error message in the energy calibration tab (#7) --- R/calibrate.R | 5 +---- R/shiny_server.R | 15 ++++++++++----- R/shiny_ui.R | 3 +++ 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/R/calibrate.R b/R/calibrate.R index c44db73d..420b9699 100644 --- a/R/calibrate.R +++ b/R/calibrate.R @@ -19,6 +19,7 @@ setMethod( # Adjust spectrum for energy shift # Get corresponding chanels lines <- as.data.frame(lines) + lines <- na.omit(lines) n <- nrow(lines) if (n < 3) { msg <- "You have to provide at least 3 lines for calibration, not %d." @@ -48,10 +49,6 @@ setMethod( definition = function(object, lines, ...) { # Get data peaks <- methods::as(lines, "data.frame") - clean <- stats::na.omit(peaks) - # Validation - if (nrow(clean) == 0) - stop("You must set the corresponding energy (keV).", call. = FALSE) # Adjust spectrum for energy shift # Return a new gamma spectrum with adjusted energy diff --git a/R/shiny_server.R b/R/shiny_server.R index b07a9fa0..083ae3c5 100644 --- a/R/shiny_server.R +++ b/R/shiny_server.R @@ -169,7 +169,6 @@ shiny_server <- function(input, output, session) { myRanges$x <- c(brush$xmin, brush$xmax) myRanges$y <- c(brush$ymin, brush$ymax) myRanges$expand <- FALSE - } else { myRanges$x <- NULL myRanges$y <- NULL @@ -183,13 +182,19 @@ shiny_server <- function(input, output, session) { energy <- vapply(X = chanel, FUN = function(i) { input[[paste0("calib_peak_", i)]] }, FUN.VALUE = numeric(1)) - if (all(is.na(energy))) - stop("XXX") peaks <- methods::initialize(myPeaks()$peaks, energy = energy) # Calibrate energy scale - spc_calib <- calibrate_energy(spc, peaks) + spc_calib <- try(calibrate_energy(spc, peaks)) # Update spectrum - myData$spectra[[input$calib_select]] <- spc_calib + if (class(spc_calib) == "try-error") { + showModal(modalDialog( + title = "Energy calibration", + spc_calib, + easyClose = TRUE + )) + } else { + myData$spectra[[input$calib_select]] <- spc_calib + } }) observeEvent(input$calib_reset, { myData$spectra[[input$calib_select]] <- myData$raw[[input$calib_select]] diff --git a/R/shiny_ui.R b/R/shiny_ui.R index f62e6e33..f57e2989 100644 --- a/R/shiny_ui.R +++ b/R/shiny_ui.R @@ -4,6 +4,9 @@ #' @keywords internal #' @noRd shiny_ui <- fluidPage( + tags$head( + tags$link(rel = "stylesheet", type = "text/css", href = "shinyApp/style.css") + ), navbarPage( "gamma", tabPanel(