Containerized {appeears} downloads

using the {appeears} package in headless docker mode

This is a contribution of by Benjamin William Barrett who is a PhD student at the Health and Biomedical Informatics track of Northwestern University Feinberg School of Medicine’s Health Sciences Integrated PhD (HSIP) program. He was geocoding healthcare encounters within a singular, privacy-preserving, environment via containerization and Docker but struggled to get the {appeears} R package authentication working.

I provided some guidance, mainly the use of a pre-created or spoofed keying, to avoid any user interaction in such a non-interactive setup. A similar approach is used in non-interactive unit testing of the package. A full description (taken from github of how to implement this in docker is provided below by Benjamin (many thanks go out to Benjamin for this write up). I hope this information might help some automate downloads of any data available on the AppEEARS API.


I was struggling for awhile to get the appeears package to function in a Docker container, and with Koen’s help finally got a working solution put together, so I’d like to document the solution here with a minimal working example in case it helps anyone else.

With Dockerfile

# Load R image
FROM rocker/r-ver:4.3.0

WORKDIR /app

# Install required packages
RUN apt-get update -y
RUN apt-get install libxml2-dev zlib1g-dev libfontconfig1-dev libssl-dev libcurl4-openssl-dev libharfbuzz-dev libfribidi-dev libfreetype6-dev libpng-dev libtiff5-dev libjpeg-dev libudunits2-dev cmake libnetcdf-dev libgdal-dev libgeos-dev libproj-dev libsqlite0-dev libsecret-1-dev libsodium23 -y

# Install R dependencies
 RUN R -e "install.packages('appeears')"

COPY entrypoint.R .

WORKDIR /tmp

ENTRYPOINT ["/usr/local/bin/Rscript", "/app/entrypoint.R"]

And entrypoint.R

# Loading necessary packages
library(appeears)

# Creating a spoofed keyring
keyring::keyring_create("appeears", password = "spoof")

# Setting the key via username and password passed as command line environmental variables
rs_set_key(
  user = Sys.getenv("USERNAME"),
  password = Sys.getenv("PASSWORD")
)

# Pulling point-based Daymet data
df <- data.frame(
  task = "Daymet",
  subtask = "US-Ha1",
  latitude = 42.5378,
  longitude = -72.1715,
  start = "2024-01-01",
  end = "2024-12-31",
  product = "DAYMET.004",
  layer = c("dayl")
)

# Building the point-based request/task
task <- rs_build_task(df = df)

# Requesting the task to be executed
rs_request(
  request = task,
  user = Sys.getenv("USERNAME"),
  transfer = TRUE,
  path = getwd(),
  verbose = TRUE
)

Activate Docker and on the command line navigate to the folder containing Dockerfile and entrypoint.R and run:

docker build -t my_container .

to build the Docker container.

Then, once the container is built, on the command line navigate to a working directory of interest and run:

docker run -e USERNAME="my_username" -e PASSWORD="my_password" --rm -v %cd%:/tmp  my_container:latest

with my_username and my_password being your NASA EarthData username and password. This was run on Windows, but if using a different system you may have to sub %cd% out for $PWD or ${PWD}.

This will download selected data from AppEEARS into your working directory.

Avatar
Koen Hufkens, PhD
Founder, Researcher

As an earth system scientist and ecologist I model ecosystem processes.

Related

Previous