Execute R script from PHP docker

I am new to docker. I have a system with 2 docker containers: Wordpress container (PHP) and RStudio container (RStudio). My question is i want to execute an R script from my PHP code (Wordpress container) “targeting” the other container (RStudio) which runs R. I am thinking of using something like :

$command = escapeshellcmd(“url-to other-container Rscript blahblahblah”);
$output = exec($command);
echo $output;

to echo the result from R.

How can this be possible?

You are using containers to isolate processes. If you run R scripts in a separate container, you can try making an API in that container to call it and the API can execute the R script locally.