############################################
## server functions for import data tab
############################################
observe({
if(!is.null(input$fileData)){
isolate({
inFile <- input$fileData
## Check file type from last three characters
fext <- unlist(strsplit(inFile$name,"[.]"))
fext <- fext[length(fext)]
if (tolower(fext) == "rds"){
tmp <- tryCatch(freadRDS(inFile$datapath),
error = function(e)e)
}else{
tmp <- tryCatch(freadCSV(inFile$datapath,
header = TRUE, #header=input$header,
sep=input$radSepData, quote=input$radQuoteData),
error = function(e){e}
)
}
## catch error
if(inherits(tmp,"error")){
## if error on reading file
str <- paste("Unable to open file:",tmp$message)
session$sendCustomMessage("messageBox", str)
return()
}
## if it has not failed then
if (tolower(fext) == "rds"){
for(ii in names(analysisRecord)){
analysisRecord[[ii]] <- tmp[[ii]]
}
}else{
nms <- colnames(tmp)
vt <- diag(1,length(nms))
colnames(vt) <- nms
rownames(vt) <- nms
analysisRecord$baseData <- tmp
analysisRecord$varTbl <- vt
analysisRecord$mdlTbl <- NULL
analysisRecord$mdlData <- NULL
analysisRecord$mdl <- NULL
}
})
}
})
output$plotData <- renderDygraph({
tmp <- analysisRecord$baseData[,input$selData]
if(is.null(tmp)){
return(NULL)
}else{
if(input$ckScaleData){
for(ii in 1:ncol(tmp)){
rng <- range(tmp[,ii],na.rm=TRUE)
tmp[,ii] <- (tmp[,ii] - rng[1])/(rng[2]-rng[1])
}
}
dygraph(tmp) %>%
dyOptions(useDataTimezone = TRUE)
}
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.