it works for one of my calculus, but the other one in IF does not. Can some one help me?
library(XLConnect)
library(Benchmarking)
require(lpSolve)
server.R
shinyServer(function(input, output) {
Jer <- reactiveValues()
observe({
if (!is.null(input$iFile)) {
inFile <- input$iFile
wb <- loadWorkbook(inFile$datapath)
sheets <- getSheets(wb)
Jer$wb <- wb
Jer$sheets <- sheets
}
})
observe({
if (!is.null(Jer$wb)) {
if (!is.null(input$sheet)){
Jer <- readWorksheet(Jer$wb, input$sheet)
print(names(Jer))
output$columns <- renderUI({
checkboxGroupInput("columns", span(strong("Escolher imputs"), style = "color:blue"),
choices = names(Jer))
})
}
}
})
Jer <- reactiveValues()
observe({
if (!is.null(input$iFile)) {
inFile <- input$iFile
wb <- loadWorkbook(inFile$datapath)
sheets <- getSheets(wb)
Jer$wb <- wb
Jer$sheets <- sheets
}
})
observe({
if (!is.null(Jer$wb)) {
if (!is.null(input$sheet)){
Jer <- readWorksheet(Jer$wb, input$sheet)
print(names(Jer))
output$colum <- renderUI({
checkboxGroupInput("colum", span(strong("Escolher outputs"), style = "color:green"),
choices = names(Jer))
})
}
}
})
chooseFile <- reactive({
inFile <- input$iFile
if (!is.null(inFile)) {
# Determine document format;
ptn <- "\\.[[:alnum:]]{1,5}$"
suf <- tolower(regmatches(inFile$name, regexpr(ptn, inFile$name)))
# Options for Excel documents;
if (suf %in% c('.xls', '.xlsx')) {
wb <- loadWorkbook(inFile$datapath)
sheets <- getSheets(wb)
output$ui <- renderUI({
list(
selectInput(inputId = "sheet", label = "Select a sheet:", choices = sheets)
)
})
return(list(path = inFile$datapath, suf = suf))
}
# Options for txt documents;
if (suf %in% c('.txt', '.csv')) {
output$ui <- renderUI({
list(
checkboxInput(inputId = 'header', label = 'First line as header', value = TRUE),
textInput(inputId = 'sep', label = 'Separator', value = " "),
textInput(inputId = 'quote', label = 'Quote', value = '\"'),
textInput(inputId = 'arg', label = 'Additional Arguments:', value = ' '),
)
})
return(list(path = inFile$datapath, suf = suf))
}
} else {return(NULL)}
})
output$contents <- renderDataTable({
objFile <- chooseFile()
if (!is.null(objFile)) {
suf <- objFile$suf
# For Excel documents;
if (suf %in% c('.xls', '.xlsx')) {
Sheet <- input$sheet
wb <- loadWorkbook(objFile$path)
dat <- readWorksheet(wb, Sheet)
return(dat)
}
# For .txt and .csv documents;
if (suf %in% c('.txt', '.csv')) {
if (is.null(input$header)) {
dat <- read.table(objFile$path)
return(dat)
} else {
if (input$arg %in% c(' ', '')) {
dat <- read.table(objFile$path, header=input$header, sep=input$sep, quote=input$quote)
return(dat)
} else {
expr.1 <- paste('"', gsub('\\', '/', objFile$path, fixed = TRUE), '"', sep = '')
expr.2 <- paste(expr.1,
paste('header =', input$header),
paste('sep =', paste("'", input$sep, "'", sep = '')),
paste('quote =', paste("'", input$quote, "'", sep = '')), input$arg, sep = ', ')
print(expr.2)
expr <- paste('read.table(', expr.2, ')', sep = '')
print(expr)
dat <- eval(parse(text = expr))
return(dat)
}
}
}
} else {return(NULL)}
})
output$summary <- renderTable({
objFile <- chooseFile()
if (!is.null(objFile)) {
suf <- objFile$suf
# For Excel documents;
if (suf %in% c('.xls', '.xlsx')) {
Sheet <- input$sheet
wb <- loadWorkbook(objFile$path)
dat <- readWorksheet(wb, Sheet)
if (input$model=="crs") {
inputs <- data.frame(dat[c(input$columns)]) # input variable at second column of the data matrix
outputs <- data.frame(dat[c(input$colum)]) # output variables
N <- dim(dat)[1] # the number of DMUs is equal to number of rows of data matrix
s <- dim(inputs)[2] # number of input variables, in this case s = 3
m <- dim(outputs)[2] # number of output variables, in this case m = 1
f.rhs <- c(rep(0,1,N),1)
f.dir <- c(rep("<=",1,N),"=")
aux <- cbind(-1*inputs,outputs)
for (i in 1:N) {
f.obj <- c(0*rep(1,s),as.numeric(outputs[i,]))
f.con <- rbind(aux ,c(as.numeric(inputs[i,]), rep(0,1,m)))
results <- lp ("max",as.numeric(f.obj), f.con, f.dir, f.rhs,scale=0, compute.sens=TRUE)
if (i==1) {
weights <- results$solution
effcrs <- results$objval
lambdas <- results$duals[seq(1,N)]
} else {
weights <- rbind(weights, results$solution)
effcrs <- rbind(effcrs , results$objval)
lambdas <- rbind(lambdas, results$duals[seq(1,N)] )
}
}
spreadsheet <- cbind(effcrs,weights)
rownames(spreadsheet) <- dat[,1]
colnames(spreadsheet) <- c('efficiency',names(inputs),names(outputs))
return(spreadsheet)
}
if (input$model=="vrs") {
inputs <- data.frame(dat[c(input$columns)]) # input variable at second column of the data matrix
outputs<-data.frame(dat[c(input$colum)]) # output variables
N <- dim(dat)[1] # the number of DMUs is equal to number of rows of data matrix
s <- dim(inputs)[2] # number of input variables, in this case s = 3
m <- dim(outputs)[2] # number of output variables, in this case m = 1
f.rhs <- c(rep(0,1,N),1)
f.dir<-c(rep("<=",1,N), "=")
aux <- cbind(-1*inputs,outputs,1,-1)
for (i in 1:N) {
f.obj<-c(rep(0,1,s),as.numeric(outputs[i,]),1,-1) # 1 and -1 represents u+ - u-
f.con <- rbind(aux,c(as.numeric(inputs[i,]),rep(0,1,m),0,0))
results <- lp ("max",as.numeric(f.obj), f.con, f.dir, f.rhs,scale=1, compute.sens=TRUE)
multipliers <- results$solution
u0 <- multipliers[s+m+1]-multipliers[s+m+2]
if (i==1) {
weights <- c(multipliers[seq(1,s+m)],u0)
effvrs <- results$objval
lambdas <- results$duals[seq(1,N)]
} else {
weights<-rbind(weights,c(multipliers[seq(1,s+m)],u0))
effvrs <- rbind(effvrs , results$objval)
lambdas <- rbind(lambdas,results$duals[seq(1,N)])
}
}
planilha <- cbind(effvrs,weights)
colnames(planilha) <- c('efficiency',names(inputs),names(outputs))
rownames(planilha) <- dat[,1]
return(planilha)
}
}
}else {return(NULL)}
})
})