在编写/调试应用程序时,我需要快速测试页面。只是使用
install()
opencpu$browser("mypage.html")
还不够,因为页面似乎没有更新。
安装后实际上需要重新启动服务器,否则页面可能不会更新。
在过去的几个月里,我编写了以下函数,我一直很高兴地使用它:
testApp <- function(page="",port="",pkg=gsub("^.*\\/","",getwd())){
require("opencpu")
require("devtools")
document();
# install the package
install();
# restart the server (or it will display cached things)
opencpu$stop();
if(port==""){
opencpu$start();
}else{
opencpu$start(port);
}
# visualize
opencpu$browse(paste0("/library/",pkg,"/www/",page));
}
然后你可以这样做:
testApp()
测试index.html
或
testApp("mypage.html")
测试特定页面。