Skip to content

Commit

Permalink
Display error message in the energy calibration tab (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
nfrerebeau committed Nov 10, 2019
1 parent de98de6 commit 3029028
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
5 changes: 1 addition & 4 deletions R/calibrate.R
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -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
Expand Down
15 changes: 10 additions & 5 deletions R/shiny_server.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]]
Expand Down
3 changes: 3 additions & 0 deletions R/shiny_ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 3029028

Please sign in to comment.