rocker-org / rocker-versioned

Run current & prior versions of R using docker
https://hub.docker.com/r/rocker/r-ver
GNU General Public License v2.0
297 stars 169 forks source link

rocker/rstudio: unsetting DISPLAY? #249

Closed rickhelmus closed 3 years ago

rickhelmus commented 3 years ago

Hello,

I am using the rocker/rstudio:4.0.3 image as a base to build Docker images with an R package I am developing. This R package depends on rcdk, which uses Java AWT for generating some image. Because DISPLAY is set, it seems that AWT wants to use an X11 environment. However, this will not work, unless you somehow configure X11 through the host I guess. The package works perfectly fine in headless mode and if R is started after unsetting DISPLAY no errors occur.

So my question is: is there any reason to keep DISPLAY being set (besides wanting host forwarding) and if not what would be a good way to unset it?

Thanks, Rick

eddelbuettel commented 3 years ago

I do not think we set it. Could that have spilled over from your session?

Demo using rstudio as well as r-base:

edd@rob:~$ docker run --rm -ti rocker/rstudio env
PATH=/usr/lib/rstudio-server/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=dc1faee78c72
TERM=xterm
R_VERSION=4.0.3
LC_ALL=en_US.UTF-8
LANG=en_US.UTF-8
R_HOME=/usr/local/lib/R
CRAN=https://packagemanager.rstudio.com/all/__linux__/focal/latest
TZ=Etc/UTC
S6_VERSION=v2.1.0.2
RSTUDIO_VERSION=latest
HOME=/root
edd@rob:~$ docker run --rm -ti rocker/r-base env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=770d380efc51
TERM=xterm
LC_ALL=en_US.UTF-8
LANG=en_US.UTF-8
R_BASE_VERSION=4.0.3
HOME=/root
edd@rob:~$ 

And I am on a machine with X11 active:

edd@rob:~$ env | grep DISPLAY
DISPLAY=:1
edd@rob:~$ 

So maybe you are doing something different locally?

rickhelmus commented 3 years ago

Hi Dirk,

Sorry, I forgot to mention this is only set from an actual RStudio session. I just confirmed this with the rocker/rstudio:4.0.3 image. (e.g. login, go to terminal tab and DISPLAY should be set)

eddelbuettel commented 3 years ago

Then it's likely not us. You may need to consult with rcdk about to possibly suppress this.

As example, package rgl added options after all those year to cleanly install and load with X11 present.

rickhelmus commented 3 years ago

Hi Dirk,

Thanks again for the quick reply. I guess RStudio or one of the other init processes sets it, as running env from the shell terminal in an RStudio session also shows it as set.

Will check with rcdk what can be done. Thanks!

rickhelmus commented 3 years ago

After some digging I can confirm it is indeed RStudio, and there doesn't seem to be a way around it... From /usr/lib/rstudio-server/R/Options.R:

...

# set default x display (see below for comment on why we need to do this)
if (is.na(Sys.getenv("DISPLAY", NA)))
   Sys.setenv(DISPLAY = ":0")

# the above two display oriented command affect the behavior of edit.data.frame
# and edit.matrix as follows: these methods will use .Internal(edit, ...) rather
# than .Internal(dataentry, ...) if DISPLAY == "" or if the .Platform$GUI is
# "unknown". since we plan on running on a server without X available we need
# to manually make sure that the DISPLAY environment variable exists and that
# the .Platform$GUI is not "unknown"

Guess I'll have to find some Java hacks instead!