I'm writing a shinyapp in which I would like to put an actionbutton to copy some code (I'm using shinyace). When I run my app for the first time, on a new session, it works fine. But when I close it and run it again, I've got an error :
Error in : Clipboard on X11 requires that the DISPLAY envvar be configured
I installed the xclip
and xsel
but the problem still exists. When I deploy my app with Shinyapps.io, I'm disconnected each time I want to use the copy-to-clipboard function.
Here are my sessionInfo()
and capabilities()
:
R version 3.6.1 (2019-07-05)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.2 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1
locale:
[1] LC_CTYPE=fr_FR.UTF-8 LC_NUMERIC=C LC_TIME=fr_FR.UTF-8
[4] LC_COLLATE=fr_FR.UTF-8 LC_MONETARY=fr_FR.UTF-8 LC_MESSAGES=fr_FR.UTF-8
[7] LC_PAPER=fr_FR.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=fr_FR.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] rsconnect_0.8.13 clipr_0.6.0 shinyAce_0.4.0 shiny_1.3.2
loaded via a namespace (and not attached):
[1] Rcpp_1.0.1 packrat_0.5.0 digest_0.6.20 later_0.8.0 bitops_1.0-6
[6] mime_0.7 R6_2.4.0 jsonlite_1.6 xtable_1.8-4 magrittr_1.5
[11] rlang_0.4.0 rstudioapi_0.10 promises_1.0.1 tools_3.6.1 RCurl_1.95-4.12
[16] httpuv_1.5.1 compiler_3.6.1 askpass_1.1 htmltools_0.3.6 openssl_1.4
jpeg png tiff tcltk X11 aqua http/ftp sockets
TRUE TRUE TRUE TRUE TRUE FALSE TRUE TRUE
libxml fifo cledit iconv NLS profmem cairo ICU
TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
long.double libcurl
TRUE TRUE
Do you know how to solve this problem ?
I also asked here : https://community.rstudio.com/t/error-in-clipboard-on-x11-requires-that-the-display-envvar-be-configured/34894
I suggest using xclip in a custom function as I do not know how to pass the DISPLAY
var to clipr::write_clip()
:
clipboard<-function(x, sep="\t", row.names=FALSE, col.names=F){
con <- pipe("xclip -selection clipboard -i -display :1", open="w") # note the 1 here
#writeChar(x, con) # for strings
write.table(x, con, sep=sep, row.names=row.names, col.names=col.names) # for table
close(con)
}
My experience is: my rstudio server must use the display that the linux terminal uses.
When I put in the linux terminal
echo $DISPLAY
gives me :1
and this works:
echo 1235 | xclip -sel clip
But inside Rstudio-server, in its system terminal $DISPLAY
gives me :0
and xclip line fails. It only works in RStudio-server after changing to DISPLAY=:1
in RStudio-server system terminal or with the -display
flag in the above function
The fact that the first time you use it, works, make me suggest to use a counter to increase the number of the display each time and see what happens.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With