Skip to content

Commit

Permalink
Follow changes in gamma
Browse files Browse the repository at this point in the history
  • Loading branch information
nfrerebeau committed Sep 19, 2024
1 parent ed1e375 commit ef286ac
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 109 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Imports:
gamma (>= 1.0.3),
ggplot2,
grDevices,
kableExtra,
gt,
khroma,
knitr,
methods,
Expand Down
5 changes: 0 additions & 5 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ importFrom(DT,datatable)
importFrom(DT,editData)
importFrom(ggplot2,theme_bw)
importFrom(grDevices,hcl)
importFrom(kableExtra,add_header_above)
importFrom(kableExtra,cell_spec)
importFrom(kableExtra,kable_styling)
importFrom(kableExtra,row_spec)
importFrom(kableExtra,spec_color)
importFrom(khroma,colour)
importFrom(khroma,scale_color_bright)
importFrom(khroma,scale_color_dark)
Expand Down
2 changes: 0 additions & 2 deletions R/gammaShiny-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
#' @importFrom DT datatable editData
#' @importFrom ggplot2 theme_bw
#' @importFrom grDevices hcl
#' @importFrom kableExtra add_header_above cell_spec kable_styling row_spec
#' spec_color
#' @importFrom knitr kable
#' @importFrom khroma colour scale_color_discreterainbow scale_color_bright
#' scale_color_highcontrast scale_color_vibrant scale_color_muted
Expand Down
136 changes: 70 additions & 66 deletions R/module_dose_server.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,34 +32,16 @@ module_dose_server <- function(input, output, session,
get(input$select_curve, envir = env_calibration)
})

user_integrate <- reactive({
req(user_curve(), user_spectra())

ni <- signal_integrate(
user_spectra(),
background = user_curve()[["Ni"]][["background"]],
range = user_curve()[["Ni"]][["range"]],
energy = FALSE,
simplify = TRUE
)

niei <- signal_integrate(
user_spectra(),
background = user_curve()[["NiEi"]][["background"]],
range = user_curve()[["NiEi"]][["range"]],
energy = TRUE,
simplify = TRUE
)

as.data.frame(cbind(ni, niei))
})

user_dose <- reactive({
req(input$sigma, input$epsilon, user_spectra(), user_curve())
withCallingHandlers(
{
dose_predict(user_curve(), user_spectra(),
sigma = input$sigma, epsilon = input$epsilon / 100)
dose_predict(
object = user_curve(),
spectrum = user_spectra(),
sigma = input$sigma,
epsilon = input$epsilon / 100
)
},
warning = function(e) {
warn <- gsub("\n|\\*", "", e$message)
Expand Down Expand Up @@ -141,56 +123,78 @@ module_dose_server <- function(input, output, session,
}
})

output$integration <- renderText({
output$integration <- gt::render_gt({
req(user_spectra())
req(user_dose())
energy_calib <- has_calibration(user_spectra())

tbl <- knitr::kable(
user_integrate(),
digits = user_settings$digits,
row.names = TRUE,
col.names = c("Value", "Error", "Value", "Error")
)
tbl <- kableExtra::kable_styling(
kable_input = tbl,
bootstrap_options = c("striped", "hover"),
full_width = TRUE, fixed_thead = TRUE
)
tbl <- kableExtra::add_header_above(
kable_input = tbl,
header = c(" " = 1, "Integration (Ni)" = 2, "Integration (NiEi)" = 2)
)
tbl <- kableExtra::row_spec(
kable_input = tbl,
row = which(!energy_calib), bold = FALSE,
color = "black", background = "orange"
)
tbl <- user_dose()
col <- which(startsWith(colnames(tbl), "signal"))

tbl <- tbl[, c(1, col)]
tbl |>
gt::gt(
rowname_col = "name"
) |>
gt::tab_spanner(
label = "Integration (Ni)",
columns = gt::ends_with("Ni")
) |>
gt::tab_spanner(
label = "Integration (NiEi)",
columns = gt::ends_with("NiEi")
) |>
gt::cols_label(
gt::starts_with("signal_Ni") ~ "Value",
gt::starts_with("signal_err") ~ "Error"
) |>
gt::fmt_number(
decimals = user_settings$digits
) |>
gt::data_color(
rows = which(!energy_calib),
palette = "orange"
) |>
gt::tab_options(table.width = "100%")
})

output$results <- renderText({
output$results <- gt::render_gt({
req(user_spectra())
req(user_dose())
energy_calib <- has_calibration(user_spectra())

tbl <- knitr::kable(
user_dose(),
digits = user_settings$digits,
row.names = FALSE,
col.names = c("Name", "Value", "Error", "Value", "Error")
)
tbl <- kableExtra::kable_styling(
kable_input = tbl,
bootstrap_options = c("striped", "hover"),
full_width = TRUE, fixed_thead = TRUE
)
tbl <- kableExtra::add_header_above(
kable_input = tbl,
header = c(" " = 1, "Dose rate (Ni)" = 2, "Dose rate (NiEi)" = 2)
)
tbl <- kableExtra::row_spec(
kable_input = tbl,
row = which(!energy_calib), bold = FALSE,
color = "black", background = "orange"
)
tbl <- user_dose()
col <- which(startsWith(colnames(tbl), "dose"))

tbl <- tbl[, c(1, col)]
tbl |>
gt::gt(
rowname_col = "name"
) |>
gt::tab_spanner(
label = "Dose rate (Ni)",
columns = gt::ends_with("Ni")
) |>
gt::tab_spanner(
label = "Dose rate (NiEi)",
columns = gt::ends_with("NiEi")
) |>
gt::tab_spanner(
label = "Mean dose rate",
columns = gt::ends_with("final")
) |>
gt::cols_label(
gt::starts_with(c("dose_Ni", "dose_final")) ~ "Value",
gt::starts_with(c("dose_err", "dose_err_final")) ~ "Error"
) |>
gt::fmt_number(
decimals = user_settings$digits
) |>
gt::data_color(
rows = which(!energy_calib),
palette = "orange"
) |>
gt::tab_options(table.width = "100%")
})

output$export_table <- downloadHandler(
Expand Down
8 changes: 4 additions & 4 deletions R/module_dose_ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ module_dose_ui <- function(id) {
),
numericInput(
inputId = ns("epsilon"),
label = "Energy calibration error (%)",
min = 0, max = 100, value = 1.5, step = 0.5
label = "Extra relative error term (%; calibration of the energy scale)",
min = 0, max = 100, value = 1.5, step = 0.05
)
),
plotOutput(outputId = ns("curve")),
Expand All @@ -99,15 +99,15 @@ module_dose_ui <- function(id) {
icon = icon("circle-radiation"),
column(
width = 12,
htmlOutput(outputId = ns("results"))
gt::gt_output(outputId = ns("results"))
)
),
tabPanel(
"Signal Integration",
icon = icon("calculator"),
column(
width = 12,
htmlOutput(outputId = ns("integration"))
gt::gt_output(outputId = ns("integration"))
)
)
)
Expand Down
49 changes: 23 additions & 26 deletions R/module_import_server.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,34 +73,31 @@ module_import_server <- function(input, output, session,
plotly::ggplotly(plot_spectra())
})

output$summary <- renderText({
output$summary <- gt::render_gt({
tbl <- user_table()
id <- tbl$name
tbl$name <- kableExtra::cell_spec(
x = tbl$name,
format = "html",
bold = TRUE,
color = "white",
background = factor(id, id, user_settings$fig_colour(length(id)))
)
tbl <- knitr::kable(
x = tbl,
format = "html",
escape = FALSE,
digits = user_settings$digits,
row.names = FALSE,
col.names = c("Name", "Date", "Live time", "Real time", "Channels",
"Min.", "Max.")
)
tbl <- kableExtra::kable_styling(
kable_input = tbl,
bootstrap_options = c("striped", "hover"),
full_width = TRUE, fixed_thead = TRUE
)
kableExtra::add_header_above(
kable_input = tbl,
header = c(" " = 5, "Energy Range" = 2)
)
pal <- unclass(user_settings$fig_colour(length(id)))

tbl |>
gt::gt() |>
gt::tab_spanner(
label = "Energy Range",
columns = gt::starts_with("energy")
) |>
gt::cols_label(
name = "Name", date = "Date", live_time = "Live time",
real_time = "Real time", channels = "Channels",
energy_min = "Min.", energy_max = "Max."
) |>
gt::fmt_number(
decimals = user_settings$digits
) |>
gt::data_color(
columns = 1,
method = "factor",
palette = pal
) |>
gt::tab_options(table.width = "100%")
})

output$export_plot <- downloadHandler(
Expand Down
2 changes: 1 addition & 1 deletion R/module_import_ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ module_import_ui <- function(id) {
fluidRow(
column(
width = 12,
tableOutput(outputId = ns("summary"))
gt::gt_output(outputId = ns("summary"))
)
)
)
Expand Down
8 changes: 4 additions & 4 deletions codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,15 @@
},
"5": {
"@type": "SoftwareApplication",
"identifier": "kableExtra",
"name": "kableExtra",
"identifier": "gt",
"name": "gt",
"provider": {
"@id": "https://cran.r-project.org",
"@type": "Organization",
"name": "Comprehensive R Archive Network (CRAN)",
"url": "https://cran.r-project.org"
},
"sameAs": "https://CRAN.R-project.org/package=kableExtra"
"sameAs": "https://CRAN.R-project.org/package=gt"
},
"6": {
"@type": "SoftwareApplication",
Expand Down Expand Up @@ -202,7 +202,7 @@
},
"SystemRequirements": null
},
"fileSize": "328.609KB",
"fileSize": "328.081KB",
"citation": [
{
"@type": "ScholarlyArticle",
Expand Down

0 comments on commit ef286ac

Please sign in to comment.