rgee icon indicating copy to clipboard operation
rgee copied to clipboard

rgee dockerfile shiny

Open pdbentley opened this issue 2 years ago • 4 comments

Hey,

We are trying to develop shinyapps which uses the rgee package. The following references have been useful:

https://github.com/csaybar/rgee-docker https://github.com/csaybar/shiny_rgee_template https://appsilon.com/r-shiny-google-earth-engine/

We are planning to host apps using google cloud run, and not shiny.io, and to do so involves using a dockerfile for the build.

Do you have any references or documents to the ones above which outline the setup approach?

Regarsd, P.

pdbentley avatar Aug 26 '22 14:08 pdbentley

had a chance to put together a working draft for a dockerfile, drawing inspiration from the links above

FROM rocker/shiny:latest

# Change permissions for R library
RUN chmod -R a+rwx /usr/local/lib/R/site-library

# Install linux dependencies for geospatial R packages
RUN apt-get update && apt-get install -y \
--no-install-recommends \
curl git libboost-all-dev \
libgdal-dev libgit2-dev libproj-dev libssl-dev  \
libudunits2-0 libudunits2-dev \
git-core \
libcurl4-gnutls-dev \
curl \
libsodium-dev \
libxml2-dev \
libicu-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
  
# install R packages
RUN R -e "install.packages(c('shiny'), dependencies=T)"
RUN R -e "install.packages(c('leaflet'), dependencies=T)"
RUN R -e "install.packages(c('rgee'), dependencies=T)"

# Install Python
RUN apt-get update && apt-get install -y \
python3 python3-pip python3-dev

# Install Python packages
RUN pip3 install numpy \
oauth2client \
earthengine-api \
jsbeautifier \
regex 

RUN  mkdir -p /home/rgee/.config/earthengine/ndef && \
echo 'EARTHENGINE_PYTHON=/usr/bin/python3\nEARTHENGINE_INIT_MESSAGE="FALSE"' > /home/rgee/.Renviron      
COPY /app/credentials /home/rgee/.config/earthengine/ndef/
  
# Remove Shiny example inherited from the base image
RUN rm -rf /srv/shiny-server/*
COPY /app/ /srv/shiny-server/
  
# change permission of the shiny folder where the app sits
RUN chmod -R 777 /srv/shiny-server

EXPOSE 3838
COPY shiny-server.sh /usr/bin/shiny-server.sh

CMD ["/usr/bin/shiny-server"]

Works for the most part, however still need to include the following lines at the start of the app.R file as this issue arises #269 which i suspect is related to the credentials file; aiming to find an approach for all build steps to sit in the dockerfile.

# need this to initialize things; without it gcloud path error
oauth_func_path <- system.file("python/ee_utils.py", package = "rgee")
utils_py <- rgee:::ee_source_python(oauth_func_path)
ee_path <- sprintf("%s/ndef", ee_utils_py_to_r(utils_py$ee_path()))
dir.create(ee_path, showWarnings = FALSE, recursive = TRUE)
file.copy(from = 'credentials', to = ee_path, overwrite = TRUE)

pdbentley avatar Aug 29 '22 10:08 pdbentley

@pdbentley Have you had success in deploying your app? I am new to shiny but I am currently using rgee with leafleat to make webmaps. I am now thinking that to have more interactivness that I need to run this through a shiny app. But I would like to know if I can host it using google cloud run first.

Have you had luck? are you using rgee with leaflet in your app?

Thank you for your response

RTjaceInnis avatar Sep 22 '23 20:09 RTjaceInnis

Hey, i have a few apps now based on the above dockerbuild plus a local copy of the credentials file in the app; and are hosted on google cloud run using leaflet.

The apps we develop are more focused on presenting landscape scale modelling results from our simulations, so are using cloud optimised geotiffs (COGS) and accessing them from a google bucket. to do this we put together an app template for folders and files to generate dockerbuilds.

While the above is a start, its not a working example; let me mock one up on github, along with the steps from shiny to docker to cloudrun; should have something up next week.

pdbentley avatar Oct 02 '23 06:10 pdbentley

@pdbentley I would be really interested in a document that describes the main steps to dockerize a shiny app that uses gee and deploying on google cloud run. If you have something just let me know. Thanks a lot

spretosg avatar Oct 30 '23 11:10 spretosg