rocker-org / rocker

R configurations for Docker
https://rocker-project.org
GNU General Public License v2.0
1.45k stars 273 forks source link

Call R from nginx+php:fpm #453

Closed mikldk closed 3 years ago

mikldk commented 3 years ago

Thanks for your effort. I am not sure that I ask the right place, but I wasn't sure where to ask so now I try here (and cross my fingers):

I am new in the docker world. For fun, I am trying to make a webserver (nginx + PHP) where I can call R from PHP.

I have a docker-compose.yml containing:

version: '3'
services:
    web:
        image: nginx:latest
        ports:
            - "80:80"
        volumes:
            - ./nginx.conf:/etc/nginx/conf.d/nginx.conf
            - ./app:/app
    r-base:
      image: rocker/r-base:latest
    php:
        image: php:fpm
        volumes:
            - ./app:/app

And app/public/index.php contains

<?php
$test = exec('R --vanilla --quiet --no-save -e "2+2;"');
var_dump($test);

As a result I get string(0) "" and at the console I get

php_1    | sh: 1: R: not found

If I in index.php instead tries exec('ls -l /usr/bin') I don't see R. I am not really sure how to expose R for PHP.

Is this rocker related? Or do you have a suggestion for where I can ask this question?

eddelbuettel commented 3 years ago

I am not sure I can help here. The r-base container adds the standard Debian package to a standard base.

Hence as it would be on any other .deb based system:

edd@rob:~$ docker run --rm -ti rocker/r-base bash -c 'type R'
R is /usr/bin/R
edd@rob:~$ 

And execution and scripts work as you would expect:

edd@rob:~$ docker run --rm -ti rocker/r-base Rscript -e '2+2'
[1] 4
edd@rob:~$ 

Maybe php or nginx or ... 'shrinks' the set of installed programs. I really don't know, and I am not sure we have a Rocker issue here. Maybe you can find some help over in php or nginx corners?

cboettig commented 3 years ago

Unrelated to rocker, but re calling R over a web interface, have you looked at the OpenCPU project? https://www.opencpu.org/

mikldk commented 3 years ago

@eddelbuettel @cboettig As always a pleasure having your advices. Thanks. I'll close this an continue my search down the suggested roads. Thanks :bow:.