Upload flexdashboard to shiny using private data from Googlesheets

Hi all.

I have created a Flexdashboard that uses restricted/private data from Googlesheets. I was able to get the dashboard to render locally on my computer, but I'm trying to push it to the web so that coworkers can use it. I'm trying to do that with Shiny but if it's possible by another means I'm fine with that. The main criteria is that the dashboard be dynamic and able to read the data from Googlesheets and update every time we update it.

I tried to reference this previous post here to guide me, but that user's data was not from Googlesheets so I think that makes things different?

I also looked for help here , here , and a million other places but at this point I think I've just confused myself. I have a working knowledge of R but basically no knowledge of what tokens, apis, etc are so I would appreciate it if someone could baby step me through this. Below is 1 iteration of what I have attempted thus far.

I run this code below.

title: "Dashboard"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
runtime: shiny

library(flexdashboard)
library(tidyverse)
library(DT)
library(googlesheets4)
library(googledrive)

gs4_auth()

gs_data <- "1Rh9XiU6OZnDRknrRi1_CdRUAeJPx1363RYtaBiYeF0M"

df <- read_sheet(gs_data)

After that, I get redirected to a page that looks like image below. I click "Continue."

After clicking continue, I get this message on my browser.

image

I return to R and my console tells me the authentication is complete.

image

I then try to deploy my project on Shiny in R using the blue icon in the image below

image

After deployment finishes running my browser launches but I get this message.

I check my logs in Shiny and see this message below


2022-01-03T21:49:28.416629+00:00 shinyapps[5390928]: 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |.......................                                               |  33%
2022-01-03T21:49:28.417097+00:00 shinyapps[5390928]: 
  |                                                                            
  |...............................................                       |  67%
2022-01-03T21:49:29.792309+00:00 shinyapps[5390928]: ✔ readr   2.1.1     ✔ forcats 0.5.1
2022-01-03T21:49:29.907564+00:00 shinyapps[5390928]: ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
2022-01-03T21:49:29.759897+00:00 shinyapps[5390928]: ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
2022-01-03T21:49:29.792307+00:00 shinyapps[5390928]: ✔ ggplot2 3.3.5     ✔ purrr   0.3.4
2022-01-03T21:49:29.792308+00:00 shinyapps[5390928]: ✔ tibble  3.1.6     ✔ dplyr   1.0.7
2022-01-03T21:49:29.907566+00:00 shinyapps[5390928]: ✖ dplyr::filter() masks stats::filter()
2022-01-03T21:49:29.907566+00:00 shinyapps[5390928]: ✖ dplyr::lag()    masks stats::lag()
2022-01-03T21:49:29.792308+00:00 shinyapps[5390928]: ✔ tidyr   1.1.4     ✔ stringr 1.4.0
2022-01-03T21:49:29.928375+00:00 shinyapps[5390928]: 
2022-01-03T21:49:29.929039+00:00 shinyapps[5390928]: 
2022-01-03T21:49:29.928377+00:00 shinyapps[5390928]: 
2022-01-03T21:49:29.929037+00:00 shinyapps[5390928]: The following objects are masked from 'package:shiny':
2022-01-03T21:49:29.929039+00:00 shinyapps[5390928]:     dataTableOutput, renderDataTable
2022-01-03T21:49:30.004571+00:00 shinyapps[5390928]: 
2022-01-03T21:49:30.004568+00:00 shinyapps[5390928]: 
2022-01-03T21:49:29.929038+00:00 shinyapps[5390928]: 
2022-01-03T21:49:30.004852+00:00 shinyapps[5390928]: 
2022-01-03T21:49:29.928377+00:00 shinyapps[5390928]: Attaching package: 'DT'
2022-01-03T21:49:30.004850+00:00 shinyapps[5390928]: The following objects are masked from 'package:googlesheets4':
2022-01-03T21:49:30.004570+00:00 shinyapps[5390928]: Attaching package: 'googledrive'
2022-01-03T21:49:30.004851+00:00 shinyapps[5390928]:     request_generate, request_make
2022-01-03T21:49:30.004851+00:00 shinyapps[5390928]: 
2022-01-03T21:49:30.196301+00:00 shinyapps[5390928]: Quitting from lines 10-21 (reprex-dashboard.Rmd) 
2022-01-03T21:49:30.197549+00:00 shinyapps[5390928]: 
2022-01-03T21:49:30.198981+00:00 shinyapps[5390928]: Warning: Error in : Can't get Google credentials.
2022-01-03T21:49:30.198982+00:00 shinyapps[5390928]: ℹ Are you running googlesheets4 in a non-interactive session? Consider:
2022-01-03T21:49:30.198983+00:00 shinyapps[5390928]: • Call `gs4_auth()` directly with all necessary specifics.
2022-01-03T21:49:30.204984+00:00 shinyapps[5390928]:   160: <Anonymous>
2022-01-03T21:49:30.198984+00:00 shinyapps[5390928]: ℹ See gargle's "Non-interactive auth" vignette for more details:
2022-01-03T21:49:30.198983+00:00 shinyapps[5390928]: • Call `gs4_deauth()` to prevent the attempt to get credentials.
2022-01-03T21:49:30.198984+00:00 shinyapps[5390928]: ℹ <https://gargle.r-lib.org/articles/non-interactive-auth.html>
2022-01-03T21:50:20.520071+00:00 shinyapps[5390928]: 
2022-01-03T21:50:20.867466+00:00 shinyapps[5390928]: 
2022-01-03T21:50:20.867468+00:00 shinyapps[5390928]: 
2022-01-03T21:50:20.868728+00:00 shinyapps[5390928]: 
2022-01-03T21:50:20.867470+00:00 shinyapps[5390928]: processing file: reprex-dashboard.Rmd
2022-01-03T21:50:20.868695+00:00 shinyapps[5390928]: 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |.......................                                               |  33%
2022-01-03T21:50:20.868719+00:00 shinyapps[5390928]:   ordinary text without R code
2022-01-03T21:50:20.868859+00:00 shinyapps[5390928]: 
  |                                                                            
  |...............................................                       |  67%
2022-01-03T21:50:20.869204+00:00 shinyapps[5390928]: label: unnamed-chunk-1
2022-01-03T21:50:21.019164+00:00 shinyapps[5390928]: 
2022-01-03T21:50:21.020617+00:00 shinyapps[5390928]: • Call `gs4_deauth()` to prevent the attempt to get credentials.
2022-01-03T21:50:21.020622+00:00 shinyapps[5390928]: ℹ <https://gargle.r-lib.org/articles/non-interactive-auth.html>
2022-01-03T21:50:21.017716+00:00 shinyapps[5390928]: Quitting from lines 10-21 (reprex-dashboard.Rmd) 
2022-01-03T21:50:21.025311+00:00 shinyapps[5390928]:   160: <Anonymous>
2022-01-03T21:50:21.020615+00:00 shinyapps[5390928]: Warning: Error in : Can't get Google credentials.
2022-01-03T21:50:21.020616+00:00 shinyapps[5390928]: ℹ Are you running googlesheets4 in a non-interactive session? Consider:
2022-01-03T21:50:21.020621+00:00 shinyapps[5390928]: • Call `gs4_auth()` directly with all necessary specifics.
2022-01-03T21:50:21.020622+00:00 shinyapps[5390928]: ℹ See gargle's "Non-interactive auth" vignette for more details:

I've tried other iterations of this process as well but as I've said before I think I've turned myself around in my understanding of what to do. Any concrete help is appreciated and please do not be afraid to baby step me through this.

Thank you.

describes the source of the problem, which is that authenticating with what looks to Googlesheets like a bot is different from using a "native client" like a web browser. The indicated fix is to supply gs4_auth() with all necessary specifics. Those are described in the docs.

If your users are read-only, this can be streamlined by using one of the write functions described here which don't involve shiny. If your users have write permission, may the good Lord help keep you safe.