1
我想在PHP代碼中使用Apache Web服務器執行R腳本(名爲script.R)。 這裏是我的R代碼裏面:我安裝軟件包,然後導入數據,那麼我可以繼續對數據的分類樹:使用Apache服務器從PHP執行R腳本
library(lubridate)
library(plyr)
library(rpart)
library(sqldf)
library(survival)
library(randomForest)
library(rpart.plot)
data=read.table(file = "t.txt",header = T,sep = ";",stringsAsFactors = T)
input=read.table(file = "file.txt",header = T,sep = ";",stringsAsFactors = T)
tree=rpart(sat~.,data,method="class")
png("tree.png", width=1000, height=800, antialias="cleartype")
plot(tree, uniform=TRUE,
main="Classification Tree")
text(tree, use.n=TRUE, all=TRUE, cex=0.8)
dev.off()
我的PHP腳本必須執行該R腳本。它們被放置在 「C:\ Apache24 \ htdocs目錄」 與 「file.txt的」 和 「t.txt」
所以我的PHP文件包含在:
<?php
exec("Rscript script.R", $results);
print_r($results);
?>
,但我得到 「陣列()」
有什麼想法?
嘗試使用'passthru()'獲取所有輸出。 'exec()'只返回最後一行:http://php.net/manual/en/function.passthru.php –
同樣的結果!它返回「1」。我想這意味着執行工作,但我沒有情節(「tree.png」)。 也許R沒有安裝在服務器上。我怎麼能檢查它是否? –