I’ve been trying to run an R file from PHP using exec().
I have searched a lot on the internet on how am I able to integrate both R and PHP.
So far I have this code in my PHP file
<?php
$command = ""C:\Program Files\R\R-4.3.0\bin\Rscript.exe" C:\xampp\htdocs\CKmeans1D.R";
exec($command, $output);
print_r($output);
and on my R file which is the CKmeans1D.R I have this code
library(Ckmeans.1d.dp)
x <- c(5,5,4,5,4.14,3.75)
result <- Ckmeans.1d.dp::Ckmeans.1d.dp(x, 3)
library(rjson)
cat(toJSON(result))
however, my PHP does not receive any output after I load it.
I tried running “C:Program FilesRR-4.3.0binRscript.exe” C:xampphtdocsCKmeans1D.R on my CMD on Windows 10 and it returns an output.
what am I missing?