error when generating html document with ggplots on remote R server using ReporteRs package(.:18048): Gtk-WARNING **: cannot open display:

巧了我就是萌 提交于 2019-12-12 05:12:38

问题


I installed ReporteRs package on a remote linux server and try to generate HTML pages with it. It works fine, but when trying to add a ggplot to the document it gives this error:

(.:18048): Gtk-WARNING **: cannot open display:

I used the solution for these kinds of problems mentioned here, (running "export DISPLAY=:0.0", before running R), but there still is an error. Now it says:

(.:19674): Gtk-WARNING **: cannot open display: :0.0

Now I am wondering if there is a way to alter the addPlot() function in such a way that it doesn't want to display anything, but just wants to put it in the document?

I use the addplot() function like this:

data <- structure(list(x = c("1", "2", "3", "4", "5", "6", "7", "8", 
"9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", 
"20"), y = c(142, 316, 223, 319, 61, 155, 400, 384, 183, 342, 
308, 167, 20, 506, 310, 164, 66, 221, 368, 345)), .Names = c("x", 
"y"), row.names = c(NA, 20L), class = "data.frame")
library(ReporteRs)
library(ggplot2)

mydoc = bsdoc( title = 'My page' )
graph <-  qplot(data$x,data$y, data)
mydoc = addPlot( mydoc, fun = print, x =graph,vector.graphic = TRUE, width = 12,par.properties = parLeft(padding = 5)) 
writeDoc( mydoc, file = "/mypage.html" )

Is there a solution or work around for this problem? Many thanks in advance!

EDIT There is a work around. First I save the plot as an image with ggsave(). Second I use addImage() of the ReporteRs package to add this image to the document. This is rather ugly because it takes much more time to process.

EDIT2 I did some more investigation. It has something to do with X11 device. Now I am wondering how to use X11 without the need for displaying. Could this be possible with an R code?

来源:https://stackoverflow.com/questions/31207085/error-when-generating-html-document-with-ggplots-on-remote-r-server-using-report

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!