inst/shinyApp/matrixModule.R
ca2b622a
 matrixUI <- function(id){
   ns <- NS(id)
282aaa63
   div(id = ns("matrix-input"),
f30da782
     radioButtons(ns("matrixSourceType"),
                  label = h5("EXPRESSION DATA MATRIX", style="font-weight: bold"),
                  choices = c("From file" = "fileMatrix",
ca2b622a
                    "From workspace" = "varMatrix")),
     conditionalPanel(
       condition = "input.matrixSourceType == 'fileMatrix'", ns = ns,
a795b9e4
       fileInput(ns("matrixFile"), "Choose expression data matrix file:",
ca2b622a
                 accept = c(
                   "text/csv",
                   "text/comma-separated-values,text/plain",
                   ".csv",".ods",".xls",".xlt"))
     ),
     conditionalPanel(
       condition = "input.matrixSourceType == 'varMatrix'", ns= ns,
a795b9e4
       selectInput(ns("matrixVar"), "Choose expression data matrix object:",
ca2b622a
                   ls(envir=.GlobalEnv))
     )
   )
 }
 
 matrixServer <- function(id){
   moduleServer( id, function(input, output, session){
     matrix <- reactive({
       if(input$matrixSourceType=="fileMatrix"){
         if(is.null(input$matrixFile)) return(NULL) #this is in order to disable "run" btn
         matrix <- data.matrix(read.csv(file=input$matrixFile$datapath, row.names = 1L))
       } else {
         if(is.null(input$matrixVar)) return(NULL)
         matrix <- get(input$matrixVar)
       }
       matrix
     }) %>% bindCache({
       if(input$matrixSourceType == "fileMatrix"){
         input$matrixFile$name
       } else {
         input$matrixVar
       }
     })
   })
a795b9e4
 }