I am trying to create a web application using R and Rook.
I saw this example http://www.road2stat.com/cn/r/rook.html and I have been able to replicate it in my command line (Calling it from inside R). But I want multiple users to be able to connect to the app at the same-time so I want to deploy it like Jeff said here - http://jeffreyhorner.tumblr.com
I have been able to replicate most of the examples that came with Rook package like Jeff stated on his blog. These include: summary.r rnorm RookTestApp
The problem I am having now is that I cant make the former example work (That is -www.road2stat) It gives me an error message every time I try to upload a file to it. This does not happen when I use the command line.
My error message is like so:
Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request.
This is my path to deploy my app
<Location /test/Visbin>
SetHandler r-handler
RFileEval /usr/lib/R/library/Rook/exampleApps/visbin.R:Rook::Server$call(newapp)
</Location>
This is the app I am trying to replicate
newapp = function(env) {
req = Rook::Request$new(env)
res = Rook::Response$new()
res$write('Choose a Binary file to Train:\n')
res$write('<form method="POST" enctype="multipart/form-data">\n')
res$write('<input type="file" name="data">\n')
res$write('xdim:\n')
res$write('<form method="POST">\n')
res$write('<input type="text" name="xdim" value="12">\n')
res$write('ydim:\n')
res$write('<form method="POST">\n')
res$write('<input type="text" name="ydim" value="25">\n')
res$write('ncolors:\n')
res$write('<form method="POST">\n')
res$write('<input type="text" name="ncolors" value="8">\n')
res$write('<input type="submit" name="Go!">\n</form>\n<br>')
myNormalize = function (target) {
return((target - min(target))/(max(target) - min(target)))
}
if (!is.null(req$POST())) {
data = req$POST()[["data"]]
hash = digest(data$tempfile, algo = "md5", file = TRUE)
destFile = file(data$tempfile, "rb")
k = floor((file.info(data$tempfile)$size/16)) - 2
doneFile = readBin(con = destFile, what = "raw", n = 2 * 8 * k)
close(destFile)
tmpFile0 = rbind(doneFile[seq(1, (2 * 8 * k) - 1, 2)], doneFile[seq(2, (2 * 8 * k), 2)])
tmpFile1 = paste(tmpFile0[1, ], tmpFile0[2, ], sep = "")
initMat = matrix(strtoi(tmpFile1, 16L), ncol = 8, byrow = TRUE)
normMat = myNormalize(initMat)
trainedSOM = kohonen::som(normMat, grid = somgrid(xdim = req$POST()[["xdim"]], ydim = req$POST()[["ydim"]], "hexagonal"))
png(paste("/tmp/", hash, ".png", sep = ""))
plot(trainedSOM, type = "dist.neighbours", palette.name = rainbow, ncolors = as.numeric(req$POST()[["ncolors"]]), main = "")
dev.off()
res$write(paste("<img src='", s$full_url("pic"), "/", hash, ".png'", " />", sep = ""))
}
res$finish()
}
And this is my command line instruction:
s = Rhttpd$new()
s$add(app = newapp, name = "visbin")
s$add(app = File$new("/tmp"), name = "pic")
s$start()
s$browse("visbin")
Can anyone please point me in the right direction or direct me to resources that will assist me in doing it.
P.S. I am using a fedora 15 and I have Rapache-1.2.0 installed.