Docker

httpgd can display R plots from Docker containers without X11 forwarding.

Basic usage

Build the image

FROM r-base:latest

RUN apt-get update \
    && apt-get install -y --no-install-recommends \
    libfontconfig1-dev \
    && apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* \
    && install2.r --error --skipinstalled --ncpu -1 \
    httpgd \
    && rm -rf /tmp/downloaded_packages
docker build . -f Dockerfile -t httpgd:test

Run the container

Bind the httpgd port with -p:

docker run --rm -it -p 8888:8888 httpgd:test R

Start the device

Inside the container, start httpgd bound to all interfaces:

httpgd::hgd(host = "0.0.0.0", port = 8888)

Open the displayed URL in your browser. To retrieve the URL later:

httpgd::hgd_url(host = "localhost")

Advanced usage

Set defaults in Rprofile

Set httpgd.host and httpgd.port options in the Rprofile so hgd() uses them automatically:

FROM r-base:latest

RUN apt-get update \
    && apt-get install -y --no-install-recommends \
    libfontconfig1-dev \
    && apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* \
    && install2.r --error --skipinstalled --ncpu -1 \
    httpgd \
    && rm -rf /tmp/downloaded_packages

RUN echo 'options(httpgd.host = "0.0.0.0", httpgd.port = 8888)' >> /etc/R/Rprofile.site

EXPOSE 8888