25

I'm getting the following error when I run shiny:

Error: Graphics API version mismatch


Listening on http://127.0.0.1:3774
Warning: Error in Cairo: Graphics API version mismatch
  [No stack trace available]

Any idea how to fix it.

My session information is below:

sessionInfo()
R version 4.1.1 (2021-08-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.2 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0

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

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

other attached packages:
 [1] leaflet_2.0.4.1   tidytable_0.6.4   forcats_0.5.1    
 [4] stringr_1.4.0     dplyr_1.0.7       purrr_0.3.4      
 [7] readr_2.0.1       tidyr_1.1.3.9000  tibble_3.1.3     
[10] ggplot2_3.3.5     tidyverse_1.3.1   ggvis_0.4.7      
[13] shiny_1.6.0       rpivotTable_0.3.0

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.7            lubridate_1.7.10     
 [3] assertthat_0.2.1      digest_0.6.27        
 [5] utf8_1.2.2            mime_0.11            
 [7] R6_2.5.0              cellranger_1.1.0     
 [9] backports_1.2.1       reprex_2.0.1         
[11] httr_1.4.2            pillar_1.6.2         
[13] rlang_0.4.11          readxl_1.3.1         
[15] rstudioapi_0.13       data.table_1.14.0    
[17] jquerylib_0.1.4       htmlwidgets_1.5.3    
[19] munsell_0.5.0         broom_0.7.9          
[21] compiler_4.1.1        httpuv_1.6.1         
[23] modelr_0.1.8          xfun_0.25            
[25] pkgconfig_2.0.3       htmltools_0.5.1.1    
[27] tidyselect_1.1.1.9000 fansi_0.5.0          
[29] crayon_1.4.1          tzdb_0.1.2           
[31] dbplyr_2.1.1          withr_2.4.2          
[33] later_1.2.0           grid_4.1.1           
[35] jsonlite_1.7.2        xtable_1.8-4         
[37] gtable_0.3.0          lifecycle_1.0.0      
[39] DBI_1.1.1             magrittr_2.0.1       
[41] scales_1.1.1          cachem_1.0.5         
[43] cli_3.0.1             stringi_1.7.3        
[45] fs_1.5.0              promises_1.2.0.1     
[47] bslib_0.2.5.1         xml2_1.3.2           
[49] ellipsis_0.3.2        generics_0.1.0       
[51] vctrs_0.3.8           Cairo_1.5-12.2       
[53] tools_4.1.1           glue_1.4.2           
[55] hms_1.1.0             crosstalk_1.1.1      
[57] rsconnect_0.8.24      yaml_2.2.1           
[59] fastmap_1.1.0         colorspace_2.0-2     
[61] rvest_1.0.1           knitr_1.33           
[63] haven_2.4.3           sass_0.4.0  
MYaseen208
  • 22,666
  • 37
  • 165
  • 309

3 Answers3

24

Starting with R 4.1.0 the graphics engine version has been upgraded. I suspect that may cause the error.

The R News for 4.1.0 state:

The graphics engine version, R_GE_version, has been bumped to 14 and so packages that provide graphics devices should be reinstalled.

So maybe re-installing the Cairo package solves the issue.

AEF
  • 5,408
  • 1
  • 16
  • 30
  • 1
    I met this issue and re-installed Cairo /tidyverse... ,but the bug not fixed. I refer to some post 'maybe updateR cause this ', so i uninstalled R and re-installed it manual, it's ok now . – anderwyang Dec 22 '21 at 08:53
  • I encountered the same error message as OP when upgrading from 4.1 to 4.2 when I tried running some plot functions from the `naniar` package. Reinstalling the `Cairo` package and `naniar`, and then restarting the kernel and reloading the packages did the trick. – Pål Bjartan May 05 '22 at 12:24
  • 1
    I had this error when using ggplot2::ggsave. Found this answer here: https://community.rstudio.com/t/graphics-error-since-intalling-r-4-1-0/105275/4 By reinstalling the ragg package the error disappeared. – Robert May 05 '22 at 12:44
24

I got this error using ggsave. I fixed it by removing and re-installing the package ragg. The version remained at 1.2.2 but now worked. I am using RStudio 2022.07.1 with R version 4.2.1

peter2108
  • 5,580
  • 6
  • 24
  • 18
  • Yes. When "Error: API graphic version incompatible" occured in shiny 1.7 we can see in browser in F12/ Network that `.Call("agg_png_c` from package `ragg` has an issue i.e. C/C++ part of `ragg`. So I've found [github/r-lib/ragg : arm64 - caught segfault - shiny app #116](https://github.com/r-lib/ragg/issues/116) and [github.com/rstudio/shiny : removing the priority of the ragg package in the shiny:::startPNG - crashing the R session #3704](https://github.com/rstudio/shiny/issues/3704) – phili_b Feb 21 '23 at 14:00
  • 2
    `options(shiny.useragg = FALSE)` resolves the issue but we have to put in all `server.R`. But the real solution, if `install.packages("ragg")` crashes, is to read the error which suggest to `sudo apt-get install libfreetype6-dev libpng-dev libtiff5-dev libjpeg-dev` for ubuntu, and run again `install.packages("ragg")` (and `options(shiny.useragg = FALSE)` is no more necessary). – phili_b Feb 21 '23 at 14:04
  • I too had an issue with ggsave but removing and reinstall ragg didn't help, I fixed it with update.packages(ask = FALSE, checkBuilt = TRUE) – myfatson Jul 31 '23 at 00:45
12

Today I faced the same problem and following Winston Chang's article Upgrading to a new version of R, I solved it by reinstalling those packages that were built with a previous version of R than the one I currently have installed:

update.packages(ask = FALSE, checkBuilt = TRUE)

I find this to be a better solution, because it is more general and will solve a recurring problem with major R updates.

Ivan
  • 195
  • 1
  • 6
  • Thank you. In my case, I just needed to restart my runtime in Google Colab after executing the statement `update.packages(ask = FALSE, checkBuilt = TRUE)`. – Md. Sabbir Ahmed Jul 21 '23 at 12:17