Skip to content
This repository has been archived by the owner. It is now read-only.

Commit

Permalink
Merge pull request #5 from HendrikSchultheis/debug
Browse files Browse the repository at this point in the history
Logging
  • Loading branch information
jenzopr authored Feb 13, 2018
2 parents 9492c1b + b266f76 commit d770d31
Show file tree
Hide file tree
Showing 12 changed files with 140 additions and 1 deletion.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Imports: shiny,
heatmaply (>= 0.14.1),
shinyBS,
shinythemes,
shinycssloaders
shinycssloaders,
log4r
RoxygenNote: 6.0.1
biocViews:
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export(pca)
export(pcaUI)
export(scatterPlot)
export(scatterPlotUI)
export(set_logger)
export(transformation)
export(transformationUI)
import(data.table)
4 changes: 4 additions & 0 deletions R/and.R
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ and <- function(input, output, session, data, show.elements = NULL, element.grou
on.exit(progress$close())
progress$set(0, message = "Apply Filter")

log_message(message = "Applying filter...", level = "INFO", token = session$token)

or.modules <- modules()

step <- 0.9 / length(or.modules)
Expand All @@ -280,6 +282,8 @@ and <- function(input, output, session, data, show.elements = NULL, element.grou

progress$set(1)

log_message(message = "Done.", level = "INFO", token = session$token)

return(list(bool = and.selection.bool, text = unlist(or.selection.text)))
})

Expand Down
4 changes: 4 additions & 0 deletions R/featureSelector.R
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ featureSelector <- function(input, output, session, data, features = NULL, featu

# reset row_selector
shiny::observeEvent(input$reset, {
log_message(message = "Filter reset", level = "INFO", token = session$token)

value(NULL)
row_selector <<- shiny::callModule(orNumeric, "row_selector", choices = choices, value = value_wrapper, label = "Select n features from the top and/or bottom of the list", stepsize = 1)
})
Expand Down Expand Up @@ -238,6 +240,8 @@ featureSelector <- function(input, output, session, data, features = NULL, featu

# first filter (and) whole set in table
select <- shiny::eventReactive(eventExpr = input$select, {
log_message(message = "Filtering data", level = "INFO", token = session$token)

data <- data.r()[and_selected()$bool]
})

Expand Down
11 changes: 11 additions & 0 deletions R/geneView.R
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ geneView <- function(input, output, session, data, metadata, level = NULL, plot.

# reset
shiny::observeEvent(input$reset, {
log_message("GeneView: reset", "INFO", token = session$token)

shinyjs::reset("genes")
shinyjs::reset("plotType")
shinyjs::reset("groupby")
Expand Down Expand Up @@ -261,6 +263,8 @@ geneView <- function(input, output, session, data, metadata, level = NULL, plot.
shinyjs::disable("download")

plot <- shiny::eventReactive(input$plot, {
log_message("GeneView: computing plot...", "INFO", token = session$token)

# enable downloadButton
shinyjs::enable("download")
clearPlot(FALSE)
Expand Down Expand Up @@ -295,6 +299,7 @@ geneView <- function(input, output, session, data, metadata, level = NULL, plot.
scale = size()$scale
)

log_message("GeneView: done.", "INFO", token = session$token)
progress$set(1, detail = "Return plot")
return(plot)
})
Expand Down Expand Up @@ -340,6 +345,8 @@ geneView <- function(input, output, session, data, metadata, level = NULL, plot.
if(clearPlot()) {
return()
} else {
log_message("GeneView: render plot interactive", "INFO", token = session$token)

#progress indicator
progress <- shiny::Progress$new()
on.exit(progress$close())
Expand All @@ -359,6 +366,8 @@ geneView <- function(input, output, session, data, metadata, level = NULL, plot.
if(clearPlot()) {
return()
} else {
log_message("GeneView: render plot static", "INFO", token = session$token)

#progress indicator
progress <- shiny::Progress$new()
on.exit(progress$close())
Expand All @@ -374,6 +383,8 @@ geneView <- function(input, output, session, data, metadata, level = NULL, plot.

output$download <- shiny::downloadHandler(filename = "geneView.zip",
content = function(file) {
log_message("GeneView: download", "INFO", token = session$token)

download(file = file, filename = "geneView.zip", plot = plot()$plot, width = plot()$width, height = plot()$height, ppi = plot()$ppi, ui = user_input())
})

Expand Down
37 changes: 37 additions & 0 deletions R/global.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

wilson.globals <- new.env(parent = emptyenv())

#' set a log4r logger used within the package
#'
#' @param logger A logger object see \code{\link[log4r]{create.logger}}. NULL to disable logging.
#' @param token Set a unique identifier for this logger.
#'
#' @details This function will save each logger in the wilson.globals environment. Each logger is stored by the name 'logger'[token] (e.g. 'logger6b821824b0b53b1a3e8f531a34d0d6e6').
#' @details Use onSessionEnded to clean up after logging. See \code{\link[shiny]{onFlush}}.
#'
#' @export
set_logger <- function(logger, token = NULL) {
if(is.null(logger) || is(logger, "logger")) {
assign(x = paste0("logger", token), value = logger, envir = wilson.globals)
}
}

#' logger message convenience function
#'
#' @param message String of message to be written in log. See \code{\link[log4r]{levellog}}.
#' @param level Set priority level of the message (number or character). See \code{\link[log4r]{levellog}}.
#' @param token Use token bound to this identifier.
#'
log_message <- function(message, level = c("DEBUG", "INFO", "WARN", "ERROR", "FATAL"), token = NULL) {
logger <- get(paste0("logger", token), envir = wilson.globals)

if(!is.null(logger)) {
switch(level,
DEBUG = log4r::debug(logger, message),
INFO = log4r::info(logger, message),
WARN = log4r::warn(logger, message),
ERROR = log4r::error(logger, message),
FATAL = log4r::fatal(logger, message)
)
}
}
11 changes: 11 additions & 0 deletions R/global_cor_heatmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ global_cor_heatmap <- function(input, output, session, data, types, plot.method

# reset ui
shiny::observeEvent(input$reset, {
log_message("Global correlation heatmap: reset", "INFO", token = session$token)

shinyjs::reset("calc")
shinyjs::reset("calc_method")
shinyjs::reset("distance")
Expand Down Expand Up @@ -328,6 +330,8 @@ global_cor_heatmap <- function(input, output, session, data, types, plot.method

# build plot object
plot <- shiny::eventReactive(input$plot, {
log_message("Global correlation heatmap: computing plot...", "INFO", token = session$token)

# enable downloadButton
shinyjs::enable("download")
# show plot
Expand Down Expand Up @@ -377,6 +381,7 @@ global_cor_heatmap <- function(input, output, session, data, types, plot.method
# update progress indicator
progress$set(1)

log_message("Global correlation heatmap: done.", "INFO", token = session$token)
return(plot)
})

Expand All @@ -389,6 +394,8 @@ global_cor_heatmap <- function(input, output, session, data, types, plot.method
if(clearPlot()) {
return()
} else {
log_message("Global correlation heatmap: render plot static", "INFO", token = session$token)

# progress indicator
progress <- shiny::Progress$new()
on.exit(progress$close())
Expand All @@ -410,6 +417,8 @@ global_cor_heatmap <- function(input, output, session, data, types, plot.method
if(clearPlot()) {
return()
} else {
log_message("Global correlation heatmap: render plot interactive", "INFO", token = session$token)

# progress indicator
progress <- shiny::Progress$new()
on.exit(progress$close())
Expand All @@ -427,6 +436,8 @@ global_cor_heatmap <- function(input, output, session, data, types, plot.method

output$download <- shiny::downloadHandler(filename = "global_correlation_heatmap.zip",
content = function(file) {
log_message("Global correlation heatmap: download", "INFO", token = session$token)

download(file = file, filename = "global_correlation_heatmap.zip", plot = plot()$plot, width = plot()$width, height = plot()$height, ppi = plot()$ppi, ui = user_input())
})

Expand Down
11 changes: 11 additions & 0 deletions R/heatmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ heatmap <- function(input, output, session, data, types, plot.method = "static",

# reset ui
shiny::observeEvent(input$reset, {
log_message("Heatmap: reset", "INFO", token = session$token)

shinyjs::reset("cluster.distance")
shinyjs::reset("cluster.method")
shinyjs::reset("clustering")
Expand Down Expand Up @@ -254,6 +256,8 @@ heatmap <- function(input, output, session, data, types, plot.method = "static",
shinyjs::disable("download")

plot <- shiny::eventReactive(input$plot, {
log_message("Heatmap: computing plot...", "INFO", token = session$token)

# enable downloadButton
shinyjs::enable("download")
clearPlot(FALSE)
Expand Down Expand Up @@ -292,6 +296,7 @@ heatmap <- function(input, output, session, data, types, plot.method = "static",

progress$set(1)

log_message("Heatmap: done.", "INFO", token = session$token)
return(plot)
})

Expand All @@ -305,6 +310,8 @@ heatmap <- function(input, output, session, data, types, plot.method = "static",
if(clearPlot()) {
return()
} else {
log_message("Heatmap: render plot interactive", "INFO", token = session$token)

#new progress indicator
progress <- shiny::Progress$new()
on.exit(progress$close())
Expand All @@ -329,6 +336,8 @@ heatmap <- function(input, output, session, data, types, plot.method = "static",
if(clearPlot()) {
return()
} else {
log_message("Heatmap: render plot static", "INFO", token = session$token)

#new progress indicator
progress <- shiny::Progress$new()
on.exit(progress$close())
Expand All @@ -350,6 +359,8 @@ heatmap <- function(input, output, session, data, types, plot.method = "static",

output$download <- shiny::downloadHandler(filename = "heatmap.zip",
content = function(file) {
log_message("Heatmap: download", "INFO", token = session$token)

download(file = file, filename = "heatmap.zip", plot = plot()$plot, width = plot()$width, height = plot()$height, ppi = plot()$ppi, ui = user_input())
})

Expand Down
9 changes: 9 additions & 0 deletions R/pca.R
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ pca <- function(input, output, session, data, types, levels = NULL, entryLabel =

#reset ui
shiny::observeEvent(input$reset, {
log_message("PCA: reset", "INFO", token = session$token)

shinyjs::reset("label")
shinyjs::reset("dimA")
shinyjs::reset("dimB")
Expand Down Expand Up @@ -230,6 +232,8 @@ pca <- function(input, output, session, data, types, levels = NULL, entryLabel =
shinyjs::disable("download")

computed.data <- shiny::eventReactive(input$plot, {
log_message("PCA: computing plot...", "INFO", token = session$token)

# enable downloadButton
shinyjs::enable("download")
clearPlot(FALSE)
Expand Down Expand Up @@ -257,6 +261,8 @@ pca <- function(input, output, session, data, types, levels = NULL, entryLabel =

progress$set(1)

log_message("PCA: done.", "INFO", token = session$token)

# show plot
shinyjs::show("pca")

Expand All @@ -282,6 +288,8 @@ pca <- function(input, output, session, data, types, levels = NULL, entryLabel =
if(clearPlot()){
return()
} else {
log_message("PCA: render plot", "INFO", token = session$token)

computed.data()$plot
}
})
Expand All @@ -297,6 +305,7 @@ pca <- function(input, output, session, data, types, levels = NULL, entryLabel =

output$download <- shiny::downloadHandler(filename = "pca.zip",
content = function(file) {
log_message("PCA: download", "INFO", token = session$token)
download(file = file, filename = "pca.zip", plot = computed.data()$plot, width = plot_width() / (computed.data()$ppi / 2.54), height = plot_height() / (computed.data()$ppi / 2.54), ppi = computed.data()$ppi, ui = user_input())
})

Expand Down
10 changes: 10 additions & 0 deletions R/scatterPlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ scatterPlot <- function(input, output, session, data, types, x.names = NULL, y.n

#reset ui
shiny::observeEvent(input$reset, {
log_message("Scatterplot: reset", "INFO", token = session$token)

shinyjs::reset("density")
shinyjs::reset("line")
shinyjs::reset("pointsize")
Expand Down Expand Up @@ -411,6 +413,8 @@ scatterPlot <- function(input, output, session, data, types, x.names = NULL, y.n
shinyjs::disable("download")

plot <- shiny::eventReactive(input$plot, {
log_message("Scatterplot: computing plot...", "INFO", token = session$token)

#enable downloadbutton
shinyjs::enable("download")
clearPlot(FALSE)
Expand Down Expand Up @@ -459,6 +463,7 @@ scatterPlot <- function(input, output, session, data, types, x.names = NULL, y.n
)

progress$set(1)
log_message("Scatterplot: done.", "INFO", token = session$token)
return(plot)
})

Expand All @@ -483,6 +488,8 @@ scatterPlot <- function(input, output, session, data, types, x.names = NULL, y.n
if(clearPlot()) {
return()
} else {
log_message("Scatterplot: render plot static", "INFO", token = session$token)

plot()$plot
}
}
Expand All @@ -492,6 +499,8 @@ scatterPlot <- function(input, output, session, data, types, x.names = NULL, y.n
if(clearPlot()) {
return()
} else {
log_message("Scatterplot: render plot interactive", "INFO", token = session$token)

#new progress indicator
progress <- shiny::Progress$new()
on.exit(progress$close())
Expand All @@ -507,6 +516,7 @@ scatterPlot <- function(input, output, session, data, types, x.names = NULL, y.n

output$download <- shiny::downloadHandler(filename = "scatterPlot.zip",
content = function(file) {
log_message("Scatterplot: download", "INFO", token = session$token)
download(file = file, filename = "scatterPlot.zip", plot = plot()$plot, width = plot()$width, height = plot()$height, ppi = plot()$ppi, ui = user_input())
}
)
Expand Down
19 changes: 19 additions & 0 deletions man/log_message.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions man/set_logger.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d770d31

Please sign in to comment.