#' Generate dynamic table
#' @param x data frame
#' @param top number of elements to show. Default all
#' @param filter_exp filter to apply of the style : column_name logical_condition value.
#' Example: "FDR < 0.1"
#' @param type analysis type. Differential expression (DE) or differential exon usage (DEU).
#' @export
top_table <- function(x, top = Inf, filter_exp = NULL, type = c("DE", "DEU")) {
type <- match.arg(type)
if(type == "DE") {
x <- x$table
}
if(!is.null(filter_exp)) {
x <- eval(parse(text = paste0("x[x$", filter_exp, ", ]")))
}
if(type == "DE") {
x$up_down <- 1*(x$logFC > 0) + -1* (x$logFC < 0)
x$logFC <- round(x$logFC, 2)
x$logCPM <- round(x$logCPM, 2)
x$LR <- round(x$LR, 2)
x$PValue <- formatC(x$PValue, format = "e", digits = 2)
x$FDR <- formatC(x$FDR, format = "e", digits = 2)
} else {
x$P.Value <- formatC(x$P.Value, format = "e", digits = 2)
x$FDR <- formatC(x$FDR, format = "e", digits = 2)
}
if(!is.infinite(top)){
x <- x[seq_len(top), ]
}
DT::datatable(x, filter = 'top', options = list(pageLength = 5, autoWidth = TRUE))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.