I am trying to run a code of R in PHP, Here are my code :
index.php
<html>
<head>
<title>PHP and R Integration Sample</title>
</head>
<body>
<div id="r-output" style="width: 100%; padding: 25px;">
<?php
// Execute the R script within PHP code
// Generates output as test.png image.
exec("Rscript sample.R");
?>
<img src="test.png?var1.1" alt="R Graph" />
</div>
</body>
</html>
sample.R
x <- rnorm(6,0,1)
png(filename="test.png", width=500, height=500)
hist(x, col="red")
dev.off()
After that I found out that I got Apache Error like this :
'Rscript' is not recognized as an internal or external command, operable program or batch file.
I tried as the comments in this link Conecting R with php, and then I updated my code :
index.php
<html>
<head>
<title>PHP and R Integration Sample</title>
</head>
<body>
<div id="r-output" style="width: 100%; padding: 25px;">
<?php
// Execute the R script within PHP code
// Generates output as test.png image.
exec("C:\Program Files\R\R-4.0.3\bin\Rscript sample.R");
?>
<img src="test.png?var1.1" alt="R Graph" />
</div>
</body>
</html>
After that update I got this message in apache :
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.
Anyone please tell me if I came wrong with interpreting the comments on the link I mentioned before. Please help me to implement R code in PHP, advise me for the best use case. Appreciate any answer.