diff --git a/R/begin.R b/R/begin.R index 7cd1b1d6..871ce6d8 100644 --- a/R/begin.R +++ b/R/begin.R @@ -51,6 +51,14 @@ getInclusionLevels <- reactive(getCategoryData()[["Inclusion levels"]]) #' @param sep Character to separate identifiers getGlobal <- function(..., sep="_") sharedData[[paste(..., sep=sep)]] +#' Get table of differential analyses +#' @note Needs to be called inside reactive function +#' @param category Character: data category (e.g. "Carcinoma 2016") +#' +#' @return Data frame of differential analyses +getDifferentialAnalyses <- function(category = getCategory()) + getGlobal(category, "differentialAnalyses") + #' Get groups from a given data type #' @note Needs to be called inside reactive function #' @param dataset Character: data set (e.g. "Clinical data") @@ -113,10 +121,12 @@ setInclusionLevels <- function(value, category = getCategory()) setGroupsFrom <- function(dataset, groups, category = getCategory()) setGlobal(category, dataset, "groups", value=groups) +#' Set table of differential analyses +#' @param table Character: differential analyses table #' @param category Character: data category (e.g. "Carcinoma 2016") #' @note Needs to be called inside reactive function -setGroupsFrom <- function(dataset, value, category = getCategory()) - setAsGlobal(paste(category, dataset, "groups", sep = "_"), value) +setDifferentialAnalyses <- function(table, category = getCategory()) + setGlobal(category, "differentialAnalyses", value=table) #' Set clinical matches from a given data type #' @note Needs to be called inside reactive function diff --git a/R/plots_differentialAnalysisTable.R b/R/plots_differentialAnalysisTable.R index 4302caba..711140b1 100644 --- a/R/plots_differentialAnalysisTable.R +++ b/R/plots_differentialAnalysisTable.R @@ -92,32 +92,38 @@ diffAnalysisTableServer <- function(input, output, session) { df3 <- cbind(df2, deltaVar, deltaMed) df4 <- data.frame(data.matrix(df3)) stats <- cbind(Event = rownames(df4), df4) - - # Columns to show in statistical table - output$showColumns <- renderUI({ - tagList( - hr(), - selectizeInput(ns("columns"), "Show columns", multiple=TRUE, - choices=colnames(stats), - selected=colnames(stats))) - }) - - # Render statistical table with the selected columns - output$statsTable <- renderDataTable({ - cols <- colnames(stats) %in% input$columns - stats[, cols] - }, options=list(pageLength=10, scrollX=TRUE)) - - output$download <- downloadHandler( - filename = paste(getCategories(), - "Differential splicing analyses"), - content = function(file) - write.table(stats, file, quote=FALSE, row.names=FALSE, - sep="\t") - ) + setDifferentialAnalyses(stats) } print(Sys.time() - time) }) + + observe({ + stats <- getDifferentialAnalyses() + if (is.null(stats)) return(NULL) + + # Columns to show in statistical table + output$showColumns <- renderUI({ + tagList( + hr(), + selectizeInput(ns("columns"), "Show columns", multiple=TRUE, + choices=colnames(stats), + selected=colnames(stats))) + }) + + # Render statistical table with the selected columns + output$statsTable <- renderDataTable({ + cols <- colnames(stats) %in% input$columns + stats[, cols] + }, options=list(pageLength=10, scrollX=TRUE)) + + output$download <- downloadHandler( + filename = paste(getCategories(), + "Differential splicing analyses"), + content = function(file) + write.table(stats, file, quote=FALSE, row.names=FALSE, + sep="\t") + ) + }) } attr(diffAnalysisTableUI, "loader") <- "plots"