CDK-R / cdkr

Integrating R and the CDK
https://cdk-r.github.io/cdkr/
42 stars 27 forks source link

view.image.2d doesn't work if no proper X11 is available #114

Open rickhelmus opened 3 years ago

rickhelmus commented 3 years ago

Hello,

The view.image.2d() function currently results in error if the DISPLAY variable is set while X11 is not actually available, eg

Error in .jcall(mi, "[B", "getBytes", as.integer(depictor$getWidth()),  : 
  java.lang.NoClassDefFoundError: Could not initialize class java.awt.GraphicsEnvironment$LocalGE

Such an (unfortunate) situation is actually happening with RStudio Docker images. Unsetting DISPLAY prior to starting R is a workaround, as Java awt automatically starts in headless mode. Setting headless manually also works:

rJava::J("java.lang.System")$setProperty("java.awt.headless","true")

I wonder if such a workaround could be implemented? I guess forcing headless for view.image.2d() should be fine in any case?

Cheers, Rick