아무리 생각해도 백임/php
[Php] Integrate R (R studio 연동)
seung_nari
2022. 12. 12. 15:13
이게 되네 짱 신기
테스트 환경
OS : 윈도우 10
개발언어 : php-8.2.0,
R-4.2.2(https://cran.r-project.org/bin/windows/base/)
R Studio(RSTUDIO-2022.07.2-576.EXE)
https://posit.co/download/rstudio-desktop/
R 설치 방법 모르면 >> https://seung-nari.tistory.com/entry/R-R-R-studio-설치-웹-연동-준비
test.php 파일
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>R Test</title>
</head>
<body>
<form method="POST" action="">
<input type="text" name="number">
<input type="submit" value="submit">
</form>
<?php
if(isset($_POST['number'])){
$number = $_POST['number'];
exec('C:\\"Program Files"\\R\\R-4.2.2\\bin\\Rscript.exe C:\inetpub\wwwroot\Rscript.R '.$number);
echo "<img src='temp.png'>";
}
?>
</body>
</html>
Rscript.R
args <- commandArgs(TRUE)
N <- args[1]
x <- rnorm(N,0,1)
png(filename = "temp.png",width = 500,height = 500)
hist(x,col = "lightblue")
dev.off()
웹 실행화면
와 신기...
자세한 공부는 내일~