我正在使用 R 中的 Rook 包构建这个应用程序:
library(Rook)
s <- Rhttpd$new()
s$start(quiet=T)
PIC.DIR = paste(getwd(), 'pic', sep='/')
my.app <- function(env){
## Start with a predefined lognormal mean and median, and allow a user to input custom values
req <- Request$new(env)
res <- Response$new()
E <- 1.5
MED <- 1
xmax <- 5
breaks <- 500
## Allow user to input custom mean/median values
if (!is.null(req$POST())){
E <- as.numeric(req$POST()[["mean"]])
MED <- as.numeric(req$POST()[["median"]])
xmax <- as.numeric(req$POST()[["xmax"]])
breaks <- as.numeric(req$POST()[["breaks"]])
}
mu <- log(MED)
sd <- sqrt(2*log(E/MED))
MO <- exp(mu - sd^2)
rate <- rlnorm(1000000, mu, sd)
today <- Sys.Date()
dt <- format(today, format="%m/%d/%y")
sc <- paste("Source: My Source, accessed ", dt)
png(file=paste(PIC.DIR, "/mypic.png", sep=""), width=1024, height=612)
h1 <- hist(rate, freq=F, col="red", xlim=c(0,xmax), breaks=breaks, main="Rate",
xlab="Rate", ylab="# of Studies", sub=sc)
dev.off()
res$write('<head>
<title> Rate Curve </title>
</head>
<h1>Rate Distribution Analysis</h1>')
res$write(paste("<img src='", s$full_url("pic"), "/mypic.png'",
"width='1024 px' height='612 px' />", sep = ""))
res$write('<p>
Input Lognormal Parameters:<form method="POST"> </br>
mean: <input type="text" name="mean" value="1.5" /> </t>
median: <input type="text" name="median" value="1" /> </br>
</br>
Graphics parameters </br>
X-axis limit: <input type="text" name="xmax" value="5" /> </t>
Histogram breaks: <input type="text" name="breaks" value="500" /> </br>
<input type="submit" name="Go" />\n</form>
</p>')
res$finish()
}
s$add(app=my.app, name='lognorm')
s$add(app = File$new(PIC.DIR), name = "pic")
s$browse('lognorm')
浏览器最初加载正常,但是当我尝试在输入中输入不同的值时,出现此错误:
未找到 R 自定义 HTTP 处理程序
无法找到 /custom/lognorm_mode 的自定义 HTTP 处理程序
是否加载了实现此 HTTP 处理程序的包?
关于如何解决这个问题的任何想法?