Error in : Clipboard on X11 requires that the DISPLAY envvar be configured

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://stackoverflow.com/questions/56942384/error-in-clipboard-on-x11-requires-that-the-display-envvar-be-configured

I think It is not possible to have access to the clients clipboard from shinyapps.io server, this might be possible if you where in your own server through a SSH connection with X11 forwarding.

Thanks, but the problem also appears when I run the app locally (without deploying it on shinyapps.io), do you know how I could fix it ?

Also, is it hard for a lambda user to apply the solution you proposed ? (and is it free ?)

We don't really have enough info to help you out. Could you ask this with a minimal REPRoducible EXample (reprex)? A reprex makes it much easier for others to understand your issue and figure out how to help, have a look at this guide, to see how to create one for a shiny app

Here's a reproducible example :

library(shiny)
library(shinyAce)
library(clipr)

init <- "text 1"
tab <- "text 2"

ui <- shinyUI(pageWithSidebar(
  headerPanel("title"),
  sidebarPanel(),
  mainPanel(
      checkboxInput("tableau", "Text 2", FALSE),
      br(),
      actionButton("copy", "Copy", width = '100%'),
      aceEditor(
        outputId = "ace",
        mode = "r",
        theme = "chrome",
        readOnly = TRUE,
        selectionId = init
      )
      )
    )
  )

server <- shinyServer(function(input, output, session) {
  observe({
    cat(input$ace, "\n")
  })

  observeEvent(input$copy, {
    write_clip(input$ace, object_type = "character")
  })
  
  observe({
    if (input$tableau) {
      updateAceEditor(session, "ace", value = tab)
    } else {
      updateAceEditor(session, "ace", value = init)
    }
  })

})

shinyApp(ui = ui, server = server)

It automatically quits when I click on "Copy" and I have the error message I posted above. And indeed, users are disconnected when they click on it in the deployed version.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.