###functions
##uploadData server functions
#function to read in the data using readr::read_delim
readData<-function(filePath, sep)
{readr::read_delim(filePath,
sep,
trim_ws = T,
skip_empty_rows = T,
col_names = T,
col_types = readr::cols(.default = readr::col_character())
)
}
#function which maps the type of file uploaded based on user selection. For example, inVAr could be input$genesep
fileType <- function(inVar){
if(inVar == "\t")
{
return("\t")
}
else (inVar == ",")
{
return(",")
}
}
#function to confirm the type of file uploaded matches the selected type
# this uses the fille uploaded (fileUp), the type of file selected (fileType - either a csv or tsv), and the file seperate from input$sep
fileCheck<- function(fileUp, fileType, fileSep){
myLines <- readLines(con = fileUp$datapath,
n = 3)
fileChk <- validate(
need(
length(strsplit(myLines[2], fileType)[[1]]) == length(strsplit(myLines[3], fileType)[[1]]),
#paste(fileUp[1])
paste("Error: the delimiter chosen does not match the file type uploaded: ", fileUp[1], sep = "")
),
need(
length(strsplit(myLines[2], fileType)[[1]]) > 1,
paste("Error: the delimiter chosen does not match the file type uploaded: ", fileUp[1], sep = "")))
if (is.null(fileChk) == TRUE) {
FileName <- readData(filePath = fileUp$datapath, sep = fileSep)
#return(FileName)
}
else {
return(fileChk)
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.