Maintenance - Mise à jour mensuelle Lundi 6 Avril 2020 entre 7h00 et 9h00

loadmoduleloc.R 2.88 KB
Newer Older
fsoubes's avatar
fsoubes committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
library(shiny)
library(shinyFiles)
library(BH)
library(data.table)


chartofa = function(datach){
  
  datach[] <- lapply( datach, factor)
  col_names <- names(datach)
  datach[col_names] <- lapply(datach[col_names] , factor)
  
  return(datach)
}


### ui end, to browse to desired folder
ui = fluidPage(
  #shinyFilesButton('directory', 'Folder select', 'Please select a folder', multiple = T),
  
  shinyDirButton('directory', 'Folder select', 'Please select a folder'),
  actionButton("importlocal", "import example"),
               tableOutput(outputId = "datpat")
)




### extracting the folder path
server = function(input, output, session) {
  
  
  volumes <- c(data = "/home/franck/MA_Trix_App/data/")

  shinyDirChoose(input, 'directory', roots=volumes, session=session)
  
    path1 <- reactive({
    return(print(parseDirPath(volumes, input$directory)))
    })
    
  ### constructing the 3 file paths
Franck Soubes's avatar
Franck Soubes committed
42

fsoubes's avatar
fsoubes committed
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
        
      csvf <- eventReactive(input$importlocal,{

        
        csvtest <- list()
        csvtest[1] <- paste0(path1(),"/TOXA_TELL_MA0020_AllChip_pData.csv")
        csvtest[2] <- paste0(path1(),"/TOXA_TELL_MA0020_AllChip_WorkingSet.csv")
        csvtest[3] <- paste0(path1(),"/All_topTableAll.csv")
        
          
          #csv <- lapply(csvtest, read.csv2, check.names = F) # benchmark read.csv wrapper
          print(csvtest[1])
          csv <- lapply(
            csvtest,
            
            #' apply the fread method for each element in the csvtest list
            #'
            #' @return list of data frame objects
            #'
            #' @export
            
            FUN = function (x)
              
              # read.table( # benchmark read.table
              #   x,
              #   sep = ";" ,
              #   dec = ",",
              #   header = T,
              #   check.names = F # good col names
              # )
              
              fread(
                x,
                data.table = F,
                check.names = F,
                header = T,
                sep = ";",
                dec = ","
              ) #benchmark fread memory speed
          )
          
          csvord = list()
          print("ok")
          for (i in 1:length(csv)) {
            if (colnames(csv[[i]][2]) == "Grp") {
              csvord[[2]] = csv[[i]]
              
            }
            else if (any(grepl("adj.P.Val" , colnames(csv[[i]]))))
            {
              csvord[[3]] = csv[[i]]
              
            }
            else
              csvord[[1]] = csv[[i]]
          }
          
          csvord[[2]] = chartofa(csvord[[2]]) # transform dataframe containing characters to factors
          row.names(csvord[[1]]) = csvord[[1]][, 1]
          colnames(csvord[[3]])[1] = "X"
          colnames(csvord[[2]])[1] = "X"
          
        
        return (csvord)
        
      })
      
    
      
      
  
}

shinyApp(ui = ui, server = server)