marinebon / infographiqR

R functions for creation of interactive intelligent infographics, ie infographiq
https://marinebon.github.io/infographiqR
MIT License
11 stars 2 forks source link

fold new authorized googlesheet4 reading into functions #65

Closed bbest closed 3 years ago

bbest commented 3 years ago

Fold functionality of noaa-onms/ocnms: test_gs4_auth.Rmd into functions for reading in a private GoogleSheet shared with shares@nms4gargle.iam.gserviceaccount.com using a JSON file for authentication:

librarian::shelf(DT, googlesheets4, here)

gsheets_sa_json <- switch(
  Sys.info()[["effective_user"]],
  bbest      = "/Volumes/GoogleDrive/My Drive/projects/nms-web/data/nms4gargle-774a9e9ec703.json",
  jai        = "/Volumes/GoogleDrive/My Drive/service-tokens/nms4gargle-774a9e9ec703.json",
  PikesStuff = "/Users/PikesStuff/Theseus/Private/nms4gargle-774a9e9ec703.json")

gsheet <- "https://docs.google.com/spreadsheets/d/1C5YAp77WcnblHoIRwA_rloAagkLn0gDcJCda8E8Efu4/edit"

Setup Service Account API Key

Reference:

Steps:

  1. Save nms4gargle-774a9e9ec703 locally, in this case to r gsheets_sa_json.

    1. Manage shares – IAM & Admin – nms4gargle – Google Cloud Platform. Added permissions to : jai.ranganathan@gmail.com, pike.spector@noaa.gov.
  2. Share [Master_OCNMS_infographic_content - Google Sheets](r gsheet) to shares@nms4gargle.iam.gserviceaccount.com.

Use

# ensure secret JSON file exists
stopifnot(file.exists(gsheets_sa_json))

# authenticate to GoogleSheets using Google Service Account's secret JSON
gs4_auth(path = gsheets_sa_json)

# access to this Google Sheet was granted to the Google Service Account
#   by Sharing with its email: shares@nms4gargle.iam.gserviceaccount.com
sheet_names(gsheet)
superjai commented 3 years ago

Create new R script file to hold new Google Sheet functionalities: ocnms_render_rmd.R

New functions: