davidgohel / ReporteRs

Note that ReporteRs has been removed from CRAN the 16th of July 2018 and is not maintained anymore. please migrate to officer.
245 stars 44 forks source link

Java error running example in RStudio Server #15

Closed rpodcast closed 10 years ago

rpodcast commented 10 years ago

I am running ReporteRs 0.5.4 installed from the GitHub repo on R 3.0.2. We have R installed in a shared filesystem so I can use the linux versions of RStudio (desktop or server versions) with this same installation of R. I am able to run the minimal FlexTable example from the FlexTable documentation page without a problem using normal R and RStudio desktop edition. However I receive a strange Java type error when running the example in RStudio Server. Here is the session output:

R version 3.0.2 (2013-09-25) -- "Frisbee Sailing"
Copyright (C) 2013 The R Foundation for Statistical Computing
Platform: x86_64-unknown-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(ReporteRs)
Loading required package: ReporteRsjars
> library( boot )
> library( plyr )
> 
> data(melanoma)
> 
> melanoma$Status = c( "Melanoma", "Alive" , "Non-melanoma" )[melanoma$status]
> melanoma$Gender = ifelse( melanoma$sex > 0, "Male", "Female" )
> melanoma$Ulceration = ifelse( melanoma$ulcer > 0, "Present", "Absent" )
> 
> data = ddply( melanoma, .(Status, Ulceration), summarize
+   , n = length( thickness )
+   , Mean = mean( thickness, na.rm = T )
+   , SD = sd( thickness, na.rm = T )
+   , Median = median( thickness, na.rm = T )
+   , Min = min( thickness, na.rm = T )
+   , Max = max( thickness, na.rm = T )
+   , Missing = sum( is.na( thickness ) )
+ )
> row.names( data ) = paste( "id", 1:nrow(data) )
> 
> print( data )
           Status Ulceration  n     Mean       SD Median  Min   Max Missing
id 1        Alive     Absent 92 1.634565 1.927020   1.13 0.10 12.88       0
id 2        Alive    Present 42 3.581190 2.577971   3.06 0.32 12.24       0
id 3     Melanoma     Absent 16 2.702500 3.349646   1.94 0.32 14.66       0
id 4     Melanoma    Present 41 4.938780 3.497797   4.04 0.97 17.42       0
id 5 Non-melanoma     Absent  7 2.097143 1.928486   1.45 0.65  6.12       0
id 6 Non-melanoma    Present  7 5.338571 4.327511   4.84 0.16 12.56       0
> 
> MyFTable = FlexTable( data = data, header.text.props = textBold() )
Error in .jcall(font, "S", "getFamily") : 
  java.lang.InternalError: Can't connect to X11 window server using ':0' as the value of the DISPLAY variable.

We have the following version of Java installed on this particular RStudio server:

> system("java -version")
java version "1.7.0_45"
OpenJDK Runtime Environment (rhel-2.4.3.3.el6-x86_64 u45-b15)
OpenJDK 64-Bit Server VM (build 24.45-b08, mixed mode

Another interesting note is the example works fine just using R from the command line on this same server. Is there some dependency on an X11 server? We usually run RStudio Server on a headless server (i.e. no X11 servers). I'm happy to provide any additional information if requested. Here's the sessionInfo()

> sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8       
 [4] LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] plyr_1.8            boot_1.3-9          ReporteRs_0.5.4     ReporteRsjars_0.0.1

loaded via a namespace (and not attached):
[1] base64_1.1  rJava_0.9-4 tools_3.0.2
davidgohel commented 10 years ago

Hi

Thanks, that's clear and I am able to reproduce the issue.

This is the same issue (go to the end directly) than: https://github.com/davidgohel/R2DOCX/issues/4

Is there some dependency on an X11 server?

Yes and no, ReporteRs needs informations on font metrics, this is done with a java.awt library. AWT package need a DISPLAY variable to be used. There is also an option to run it with no graphical envirironment.

-Djava.awt.headless=true

However, I will get back to you when I will have a solution! Hopefully today or tomorrow. I think I will have to modify the java code...

David

davidgohel commented 10 years ago

But I am also surprised that it works with R and not with RStudio server (I recently face weird issue with rJava that was ok with R but not with RStudio Web server). I don't understand what is going on here...

davidgohel commented 10 years ago

Hi,

The version 0.5.5 should fix the issue. Could you please test and tell me if it is ok?

David

rpodcast commented 10 years ago

Hi David,

I just tested this out on a few different RStudio Server installations and now it works! Thank you very much for the quick turnaround to fix the issue. I'm looking forward to using this package as part of my R markdown and Shiny app workflow.