Unable to open connecting to X11 display ''

Dear R studio Community.

I'm using the latest version of R-Studio-Server and Shiny-Server (open source).

Why does app.R not work in shiny-server even though it works on R-studio server?

Here is the source code (same as basic shiny app demo)

library(shiny)

# Define UI for application that draws a histogram
   
   # Application title
   titlePanel("Old Faithful Geyser Data"),
ui <- fluidPage(
   
   # Sidebar with a slider input for number of bins 
   sidebarLayout(
      sidebarPanel(
         sliderInput("bins",
                     "Number of bins:",
                     min = 1,
                     max = 50,
                     value = 30)
      ),
      
      # Show a plot of the generated distribution
      mainPanel(
         plotOutput("distPlot")
      )
   )
)

# Define server logic required to draw a histogram
server <- function(input, output) {
   
   output$distPlot <- renderPlot({
      # generate bins based on input$bins from ui.R
      x    <- faithful[, 2] 
      bins <- seq(min(x), max(x), length.out = input$bins + 1)
      
      # draw the histogram with the specified number of bins
      hist(x, breaks = bins, col = 'darkgray', border = 'white')
   })
}

# Run the application 
shinyApp(ui = ui, server = server)

Listening on http://127.0.0.1:46479
Warning in pngfun(filename = filename, width = width, height = height, res = res,  :
  unable to open connection to X11 display ''
Warning: Error in .External2: unable to start device PNG
  127: pngfun
  126: startPNG
  125: drawPlot
  111: <reactive:plotObj>
   95: drawReactive
   82: origRenderFunc
   81: output$distPlot
    1: runApp

output of capabilities()

> capabilities()
       jpeg         png        tiff       tcltk         X11        aqua
       TRUE        TRUE        TRUE        TRUE       FALSE       FALSE
   http/ftp     sockets      libxml        fifo      cledit       iconv
       TRUE        TRUE        TRUE        TRUE        TRUE        TRUE
        NLS     profmem       cairo         ICU long.double     libcurl
       TRUE       FALSE        TRUE        TRUE        TRUE        TRUE
  • version information
> version()
platform       x86_64-pc-linux-gnu
arch           x86_64
os             linux-gnu
system         x86_64, linux-gnu
status
major          3
minor          6.3
year           2020
month          02
day            29
svn rev        77875
language       R
version.string R version 3.6.3 (2020-02-29)
nickname       Holding the Windsock

it might be related to "Shiny-server on ubuntu 16 error: "unable to open connection to X11 display ''"

but re-installation does not solve the issue in my case.
(I use 'sudo' command to install R using 'apt' command)

thanks.

1 Like

Are all your packages installed system wide so the shiny user can access them?

1 Like

Yes, I checked them. Shiny can access all packages.

However, I found an error after I switched my account to shiny user.

bash: cannot set terminal process group (-1): Inappropriate ioctl for device
bash: no job control in this shell

What is the "ioctl" ? is it related to the problem?

I got the solution from Yihui's post on "https://stackoverflow.com/questions/17243648/cant-display-png"

adding the following line on the top of ShinyApp code solved my problem.

options(bitmapType='cairo')

thanks !

1 Like

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