2

When I try to render the correlation scatter plot in Shiny app using ggplot following error appears: Failed to create Cairo backend!

   output$model <- renderPlot({

      k <- dataIn()
      cormat <- round(cor(k),2)
      library(reshape2) 
      melted_cormat <- melt(cormat)

      wyk3 <- ggplot(data = melted_cormat, aes(x=Var1, y=Var2, fill=value)) 

      return(wyk3)
    }) 

Here's what i get in the Console:

Warning: Error in Cairo: Failed to create Cairo backend!
  128: Cairo
  127: pngfun
  126: startPNG
  125: drawPlot
  111: <reactive:plotObj>
   95: drawReactive
   82: origRenderFunc
   81: output$model
    1: shiny::runApp

I don't know what might be the problem, other ggplot scatterplots se to are rendering properly, also using x11() in regular Rscript the scatterplot appears.

Could you help me, and explain what's wrong with what I am doing?

'> sessionInfo()
R version 3.5.2 (2018-12-20)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=Polish_Poland.1250  LC_CTYPE=Polish_Poland.1250    LC_MONETARY=Polish_Poland.1250
[4] LC_NUMERIC=C                   LC_TIME=Polish_Poland.1250    

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

other attached packages:
[1] reshape_0.8.8   ggplot2_3.1.0   lattice_0.20-38 shiny_1.2.0    

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.0       pillar_1.3.1     compiler_3.5.2   later_0.7.5      plyr_1.8.4      
 [6] bindr_0.1.1      tools_3.5.2      digest_0.6.18    jsonlite_1.6     tibble_2.0.1    
[11] gtable_0.2.0     pkgconfig_2.0.2  rlang_0.3.1      rstudioapi_0.9.0 yaml_2.2.0      
[16] bindrcpp_0.2.2   withr_2.1.2      dplyr_0.7.8      grid_3.5.2       tidyselect_0.2.5
[21] glue_1.3.0       R6_2.3.0         purrr_0.2.5      magrittr_1.5     scales_1.0.0    
[26] promises_1.0.1   htmltools_0.3.6  assertthat_0.2.0 mime_0.6         xtable_1.8-3    
[31] colorspace_1.3-2 httpuv_1.4.5.1   labeling_0.3     lazyeval_0.2.1   munsell_0.5.0   
[36] crayon_1.3.4     Cairo_1.5-9 
JDowN
  • 21
  • 4
  • 1
    There are certainly issues in the code, though I'm not getting any errors like you're describing. Can you provide your `sessionInfo()` to see if that helps? – phalteman Jan 14 '19 at 23:14
  • You also need to provide a `geom` in your call to `ggplot`. Without that, you won't get any data, but I don't imagine that's causing your problem, which I can't replicate. – phalteman Jan 15 '19 at 05:55

1 Answers1

1

I am late to the party. Generally, this error occurs because of some problem in the ui. The way I solved this problem is by putting the following code in the ui: plotOutput('ggPlot',inline = F). With plotOutput('ggPlot',inline = T), I am getting the same error.

Stat-R
  • 5,040
  • 8
  • 42
  • 68