emacs-ess / ESS

Emacs Speaks Statistics: ESS
https://ess.r-project.org/
GNU General Public License v3.0
613 stars 160 forks source link

Can not show plot graphics of R running in docker container through ESS #1069

Closed ryamy closed 3 years ago

ryamy commented 3 years ago

I really love emacs-ess / R and have been using that on local machine. Now I would like to access R running on docker container through ess.
I could connect R running on docker through ESS by following site(https://gtown-ds.netlify.app/2017/08/16/docker-emacs/), but when plotting, it does not work. Is there any good way to use ESS/R with graphics on docker?

R console log

$ R
R

R version 4.0.3 (2020-10-10) -- "Bunny-Wunnies Freak Out"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> 
> 
#(connection by ess-remote)

> options(pager='cat')
options(pager='cat')
> options(STERM='iESS', str.dendrogram.last="'", editor='emacsclient', show.error.locations=TRUE)
<t="'", editor='emacsclient', show.error.locations=TRUE)
> a <- c(-10:10)
> b <- a ^ 3
> 
+ plot(a, b)
+ 

> plot(a, b)
Could not find ':' in DISPLAY: Mac
Error in .External2(C_X11, d$display, d$width, d$height, d$pointsize,  : 
  unable to start device X11cairo
In addition: Warning message:
In (function (display = "", width, height, pointsize, gamma, bg,  :
  unable to open connection to X11 display ''

Dockerfile

FROM rocker/rstudio:4.0.3

## Update and install extra packages
RUN apt-get update \
  && apt-get install -y --no-install-recommends \
    openssh-server \
    libx11-dev \
    x11proto-core-dev \
    xauth \
    xfonts-base \
    xvfb \
  && apt-get clean \
  && rm -rf /var/lib/apt/lists/

RUN mkdir /var/run/sshd

RUN echo 'root:root' | chpasswd

RUN sed -ri 's/^PermitRootLogin\s+.*/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config
RUN sed -ri 's/X11Forwarding no/X11Forwarding yes/g' /etc/ssh/sshd_config
RUN sed -ri 's/#X11UseLocalhost yes/X11UseLocalhost no/g' /etc/ssh/sshd_config

EXPOSE 22

CMD    ["/usr/sbin/sshd", "-D"]

OS: macOS 11.0.1 emacs version: GNU Emacs 27.1 ESS version: 20201101.811

JHonaker commented 3 years ago

You probably need to setup X forwarding.

It's usually as simple as using the -X and sometimes -t flags. I'm not super familiar with Docker, but the line is usually something like ssh -X -t user@server.

ryamy commented 3 years ago

Thanks for your comment.

The problem was solved when I used rocker/verse image instead of rocker/rstudio image without any modification. I suppose perhaps rocker/rstudio image does not contain X components.

And I think procedure written in following url is better rather than using build ssh-server in container. Dockerized UI Apps in Docker for Desktop MacOS 2018+