vscode-R icon indicating copy to clipboard operation
vscode-R copied to clipboard

unable to open connection to X11 display

Open nick-youngblut opened this issue 1 year ago • 3 comments

Describe the bug

I've created my own Docker container with R4.2.1, instead of using a Rocker container. Running R code in VS Code works, except for plotting, in which I get unable to open connection to X11 display '' errors when trying to plot anything.

To Reproduce

Dockerfile:

FROM ubuntu:22.04

# Set R version
ENV R_BASE_VERSION 4.2.1

## Set a default user. Available via runtime flag `--user docker`
## Add user to 'staff' group, granting them write privileges to /usr/local/lib/R/site.library
## User should also have & own a home directory (for rstudio or linked volumes to work properly).
RUN useradd docker && \
    mkdir /home/docker && \
    chown docker:docker /home/docker && \
    addgroup docker staff

# Install required dependencies and clean up the cache
RUN apt-get update && \
    DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
        software-properties-common \
        libx11-6 \
        libxt6 \
        libxml2-dev \
        libpq-dev \
        libssl-dev \
        libsodium-dev \
        libfontconfig1-dev \
        libharfbuzz-dev \
        libfribidi-dev \
        libfreetype6-dev \
        libpng-dev \
        libtiff5-dev \
        libjpeg-dev \
        libcurl4-openssl-dev \
        libmariadb-dev \
        libbz2-dev \
        liblzma-dev \
        libpcre2-dev \
        libicu-dev \
        libjpeg8-dev \
        libcairo2-dev \
        libxt-dev \
	libreadline-dev \
	zlib1g-dev \
        libgit2-dev \
        xdg-utils \
        cmake \
        dirmngr \
        gnupg2 \
        curl \
        wget \
        git \
        tree \
        screen \
	gfortran \
        locales \
        ca-certificates \
        build-essential \
        xz-utils && \
    echo "deb http://cloud.r-project.org/bin/linux/ubuntu $(lsb_release -cs)-cran40/" > /etc/apt/sources.list.d/cran.list && \
    curl -fsSL https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | gpg --dearmor -o /usr/share/keyrings/cloud.r-project.gpg && \
    echo "deb [signed-by=/usr/share/keyrings/cloud.r-project.gpg] http://cloud.r-project.org/bin/linux/ubuntu $(lsb_release -cs)-cran40/" | tee /etc/apt/sources.list.d/cran.list && \
    apt-get update && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

## Configure default locale
RUN echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen && \
    locale-gen en_US.utf8 && \
    /usr/sbin/update-locale LANG=en_US.UTF-8

ENV LC_ALL en_US.UTF-8
ENV LANG en_US.UTF-8
ENV TZ=Etc/UTC

# Download, compile, and install R 4.2.1
RUN curl -O https://cran.r-project.org/src/base/R-4/R-${R_BASE_VERSION}.tar.gz && \
    tar -xf R-${R_BASE_VERSION}.tar.gz && \
    cd R-${R_BASE_VERSION} && \
    ./configure --prefix=/usr/local --enable-R-shlib --with-blas --with-lapack && \
    make && \
    make install && \
    cd .. && \
    rm -rf R-${R_BASE_VERSION}*

# Set the working directory
WORKDIR /usr/src/app

# Install R packages
RUN R -e "install.packages('renv', repos = 'https://cloud.r-project.org/')" && \
  R -e "renv::init()" && \
  R -e "renv::install(c('dplyr', 'tidyr', 'ggplot2', 'glue', 'stringr', 'readxl', 'lubridate', 'data.table', 'tidytable', 'httr', 'aws.s3', 'aws.signature', 'haven', 'purrr', 'languageserver', 'jsonlite', 'Cairo'))" && \
  R -e "renv::clean()"

devcontainer:

{
    "name": "r4",
    "image": "320240270431.dkr.ecr.us-west-2.amazonaws.com/r_base:4.2.1",
    "postCreateCommand": "bash .devcontainer/setup.sh",
    "customizations": {
        "vscode": {
            "extensions": [
                "GitHub.copilot",
                "eamodio.gitlens",
                "codezombiech.gitignore",
                "REditorSupport.r",
                "Gruntfuggly.todo-tree",
                "ms-azuretools.vscode-docker",
                "ms-vscode-remote.remote-ssh"
	       ]
            }
	},
    "features": {
        "ghcr.io/devcontainers/features/aws-cli:1": {
            "version": "latest"
        }
    }
}

sessionInfo:

R version 4.2.1 (2022-06-23)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.2 LTS

Matrix products: default
BLAS:   /usr/local/lib/R/lib/libRblas.so
LAPACK: /usr/local/lib/R/lib/libRlapack.so

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 datasets  utils     methods   base     

other attached packages:
[1] Cairo_1.6-0   tidyr_1.3.0   dplyr_1.1.1   ggplot2_3.4.2

loaded via a namespace (and not attached):
 [1] magrittr_2.0.3   tidyselect_1.2.0 munsell_0.5.0    colorspace_2.1-0
 [5] R6_2.5.1         rlang_1.1.0      fansi_1.0.4      tools_4.2.1     
 [9] grid_4.2.1       gtable_0.3.3     utf8_1.2.3       cli_3.6.1       
[13] withr_2.5.0      tibble_3.2.1     lifecycle_1.0.3  purrr_1.0.1     
[17] farver_2.1.1     vctrs_0.6.1      glue_1.6.2       labeling_0.4.2  
[21] compiler_4.2.1   pillar_1.9.0     generics_0.1.3   scales_1.2.1    
[25] jsonlite_1.8.4   renv_0.17.3      pkgconfig_2.0.3 

Can you fix this issue by yourself? (We appreciate the help)

No (it seems not even with GPT4 support)

nick-youngblut avatar Apr 10 '23 20:04 nick-youngblut

Using httpgd works for viewing the plots but I do have to explicitly load httpgd and create the webserver:

library(httpgd)
hgd()
hgd_browse()
plot(1:10)

In case this helps:

capabilities()
       jpeg         png        tiff       tcltk         X11        aqua 
       TRUE        TRUE        TRUE       FALSE       FALSE       FALSE 
   http/ftp     sockets      libxml        fifo      cledit       iconv 
       TRUE        TRUE       FALSE        TRUE        TRUE        TRUE 
        NLS       Rprof     profmem       cairo         ICU long.double 
       TRUE        TRUE       FALSE        TRUE        TRUE        TRUE 
    libcurl 
       TRUE 

nick-youngblut avatar Apr 10 '23 20:04 nick-youngblut

Did you enable r.plot.useHttpgd in your vscode settings? If enabled, the httpgd plot viewer should automatically pop out as a new tab.

renkun-ken avatar Apr 24 '23 09:04 renkun-ken

This issue is stale because it has been open for 365 days with no activity.

github-actions[bot] avatar Apr 24 '24 01:04 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar May 09 '24 01:05 github-actions[bot]