The hardware and bandwidth for this mirror is donated by dogado GmbH, the Webhosting and Full Service-Cloud Provider. Check out our Wordpress Tutorial.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]dogado.de.
Google Earth Engine (GEE) allows users to create apps by three different approaches: user tokens, service accounts and client-side authentication. In this tutorial, we will get focus on the first option.
An EEtk is a 100-character text string (OAuth2 credential) stored on your local system that is used to identify and authenticate users (See Figure below). In other words, it will permit to connect the EE Web REST API with their local system.
In rgee the authentication procedure is triggered internally by ee_Initialize. This function will search for the ‘credentials’ file (it stores the EEtk) on the path: ~/.config/earthengine/.
library(rgee)
sprintf("%s/credentials", dirname(rgee::ee_get_earthengine_path()))
If the file exists, then an Oauth2 Credential object is created using a refresh token grant. This refresh token must come from a Google account registered in GEE if not a Bad Request error will be invoked. Once the Oauth2 Credential is successfully loaded, it is dynamically passed to all EE methods (See Initialize) in order to realize independent calls to the Web REST API. As you realize, the credentials file is crucial to interact with the EE API and if it does not exist on your system, it will simply not be possible to use rgee.
Deploying a rgee application can be a bit tricky, as you must perform the following task:
The first step is automatically accomplished for shinyapps.io. On the other hand, the second and third steps need to configure manually the virtual machine. To make the process straightforward we create shiny_rgee template.
To use shiny_rgee template, first download it by running on terminal:
git clone https://github.com/csaybar/shiny_rgee_template.git
Load the rgeeApp.Rproj and modify the .Renviron file according to their personal token user information. It is available in your shinyapps profile https://www.shinyapps.io/admin/#/tokens.
SHINY_ACC_NAME="your_account_name"
TOKEN="a_token_you_got_from_shinyapps.io"
SECRET="a_secret_you_recieved_fromshinyapps.io"
MASTERNAME="name_of_the_shiny_app"
Finally run the deploy.R file.
library(reticulate)
library(rsconnect)
library(rgee)
# 1. Create the credentials file
ee_Initialize()
# 2. Copy credentials file to the project folder
file_credentials <- sprintf("%s/credentials", dirname(rgee::ee_get_earthengine_path()))
file.copy(file_credentials, to = ".")
# 3. Set ShinyApps account info
# FIRST MODIFY LOCAL .Renviron!!
error_on_missing_name <- function(name){
var <- Sys.getenv(name, unset=NA)
if(is.na(var)){
stop(paste0("cannot find ",name),call. = FALSE)
}
gsub("\"", '',var)
}
setAccountInfo(name = error_on_missing_name("SHINY_ACC_NAME"),
token = error_on_missing_name("TOKEN"),
secret = error_on_missing_name("SECRET"))
# 4. Run the application
deployApp(
appFiles = c("app.R", "utils.R", "credentials"),
appTitle = "rgee_app_demo",
lint = FALSE
)
# 5. Delete EE credentials file
file.remove("credentials")
After a couple of minutes, the app will be available on shinyapps.io. See our live demo in https://cesar-aybar.shinyapps.io/rgee_app_demo/.
These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.
Health stats visible at Monitor.