How to add additional packages to R?

Hi,

I need some additonal packages added to R, which is used in the Jupyter Notebook R Stack.
So far I tried to modify the corresponding Dockerfile (added some packages (r-qboxplot, r-hhi,…))

ARG OWNER=jupyter
ARG BASE_CONTAINER=$OWNER/minimal-notebook
FROM $BASE_CONTAINER

LABEL maintainer="Jupyter Project <jupyter@googlegroups.com>"

# Fix: https://github.com/hadolint/hadolint/wiki/DL4006
# Fix: https://github.com/koalaman/shellcheck/wiki/SC3014
SHELL ["/bin/bash", "-o", "pipefail", "-c"]

USER root

# R pre-requisites
RUN apt-get update --yes && \
    apt-get install --yes --no-install-recommends \
    fonts-dejavu \
    unixodbc \
    unixodbc-dev \
    r-cran-rodbc \
    gfortran \
    gcc && \
    apt-get clean && rm -rf /var/lib/apt/lists/*

USER ${NB_UID}

# R packages including IRKernel which gets installed globally.
# r-e1071: dependency of the caret R package
RUN mamba install --quiet --yes \
    'r-base' \
    'r-caret' \
    'r-crayon' \
    'r-devtools' \
    'r-e1071' \
    'r-forecast' \
    'r-hexbin' \
    'r-htmltools' \
    'r-htmlwidgets' \
    'r-irkernel' \
    'r-nycflights13' \
    'r-randomforest' \
    'r-rcurl' \
    'r-rmarkdown' \
    'r-rodbc' \
    'r-rsqlite' \
    'r-shiny' \
    'r-tidyverse' \
    'r-qboxplot' \
    'r-hhi' \
    'r-ineq' \
    'r-hmisc' \
    'r-BSDA' \
    'r-moderndive' \
    'r-mosaic' \
    'r-micEconIndex' \
    'unixodbc' && \
    mamba clean --all -f -y && \
    fix-permissions "${CONDA_DIR}" && \
    fix-permissions "/home/${NB_USER}"

# `r-tidymodels` is not easy to install under arm
RUN set -x && \
    arch=$(uname -m) && \
    if [ "${arch}" == "x86_64" ]; then \
        mamba install --quiet --yes \
            'r-tidymodels' && \
            mamba clean --all -f -y && \
            fix-permissions "${CONDA_DIR}" && \
            fix-permissions "/home/${NB_USER}"; \
    fi;

Unfortunately, when I try to build this Dockerfile I get the error

#6 5.861 Encountered problems while solving:                                                                                                                                
#6 5.861   - nothing provides requested r-qboxplot
#6 5.861   - nothing provides requested r-hhi
#6 5.861   - nothing provides requested r-moderndive
#6 5.861   - nothing provides requested r-miceconindex
#6 5.861   - nothing provides r-ggrepel needed by r-mosaic-1.8.3-r40hc72bb7e_0
#6 5.861   - package r-bsda-1.2.0-r40hc72bb7e_0 requires r-base >=4.0,<4.1.0a0, but none of the providers can be installed

Any ideas how to add some additional packages another way?

PS: I’m running jupyterhub via docker-compose as described here

TIA!
Best,
Alex

If you’re absolutely committed to using conda-forge (which is a fine goal, as it would benefit other users), there’s more work ahead.

It’s like it says: those packages aren’t available from conda-forge, and it all starts with staged-recipes.

You can either:

Even as this “works,” the r installed by conda won’t be able to find it.

You may want to everything with the system r, a la: install.R and using that package manager directly.

1 Like

Hi,
thank you very much for your answer. Finally, I managed it by creating a new “private_Dockerfile” which is used for a singleuser:

ARG OWNER=jupyter
ARG BASE_CONTAINER=$OWNER/minimal-notebook
FROM $BASE_CONTAINER

# Fix: https://github.com/hadolint/hadolint/wiki/DL4006
# Fix: https://github.com/koalaman/shellcheck/wiki/SC3014
SHELL ["/bin/bash", "-o", "pipefail", "-c"]

USER root

# R pre-requisites
RUN apt-get update --yes && \
    apt-get install --yes --no-install-recommends \
    fonts-dejavu \
    unixodbc \
    unixodbc-dev \
    r-cran-rodbc \
    gfortran \
    gcc && \
    apt-get clean && rm -rf /var/lib/apt/lists/*


USER ${NB_UID}

# R packages including IRKernel which gets installed globally.
# r-e1071: dependency of the caret R package
RUN mamba install --quiet --yes \
    'r-base' \
    'r-caret' \
    'r-crayon' \
    'r-devtools' \
    'r-e1071' \
    'r-forecast' \
    'r-hexbin' \
    'r-htmltools' \
    'r-htmlwidgets' \
    'r-irkernel' \
    'r-nycflights13' \
    'r-randomforest' \
    'r-rcurl' \
    'r-rmarkdown' \
    'r-rodbc' \
    'r-rsqlite' \
    'r-shiny' \
    'r-tidyverse' && \
    mamba clean --all -f -y && \
    fix-permissions "${CONDA_DIR}" && \
    fix-permissions "/home/${NB_USER}"

# `r-tidymodels` is not easy to install under arm
RUN set -x && \
    arch=$(uname -m) && \
    if [ "${arch}" == "x86_64" ]; then \
        mamba install --quiet --yes \
            'r-tidymodels' && \
            mamba clean --all -f -y && \
            fix-permissions "${CONDA_DIR}" && \
            fix-permissions "/home/${NB_USER}"; \
    fi;

RUN R -e "install.packages('qboxplot',dependencies=TRUE, repos='http://cran.rstudio.com/')"
RUN R -e "install.packages('hhi',dependencies=TRUE, repos='http://cran.rstudio.com/')"
RUN R -e "install.packages('ineq',dependencies=TRUE, repos='http://cran.rstudio.com/')"
RUN R -e "install.packages('hmisc',dependencies=TRUE, repos='http://cran.rstudio.com/')"
RUN R -e "install.packages('BSDA',dependencies=TRUE, repos='http://cran.rstudio.com/')"
RUN R -e "install.packages('moderndive',dependencies=TRUE, repos='http://cran.rstudio.com/')"
RUN R -e "install.packages('mosaic',dependencies=TRUE, repos='http://cran.rstudio.com/')"
RUN R -e "install.packages('micEconIndex',dependencies=TRUE, repos='http://cran.rstudio.com/')"

…and building it …

docker build -f private_Dockerfile -t jupyterhub-user --build-arg JUPYTERHUB_VERSION=0.9.2 --build-arg DOCKER_NOTEBOOK_IMAGE=jupyter/r-notebook:r-3.6.3 singleuser   

and then

docker-compose up -d --build

When I enter the jupyterhub I was suprised to find a new UX:

When I switched back to the standard Dockerfile for singleuser i.e.

make notebook_image

with DOCKER_NOTEBOOK_IMAGE=jupyter/r-notebook:r-3.6.3
I get the “old” UX back:

So, little bit offtopic:
How is it possible to switch between the two different UX?
Does it depend on DOCKER_NOTEBOOK_IMAGE=jupyter/r-notebookXXXXX?

TIA,
Alex

1 Like

jupyterlab running on jupyter_server has been the default UI for some years at this point. At present, it also serves the classic UI, which can be started from the URL /tree.

When opening jupyterlab, you can use the main menu to get to Help » Launch Classic Notebook.

You can pre-configure launching /tree in ~/.jupyter/jupyter_config.json#ServerApp/default_url, a la:

{
  "ServerApp": {
    "default_url": "/tree"
  }
}
1 Like