I am trying to create two distinct shiny apps that interact with each other. The goal is for the first app to create a google sheet that is accessible to the second app, while authentication is only required for the user of the first app.
One way I thought of doing this was to upload the cached token created by the first app to google drive, available to anyone via link, and have the second app use that link to authenticate with the token stored there. From there, the aforementioned google sheet could be accessed.
I am a newbie when it comes to these authentication procedures, so I'm not sure if this is possible or if it requires some alternative means.
Here are the ui and server components of the first app
# App 1
library(shiny)
library(shinysurveys)
library(googlesheets4)
library(googledrive)
ui <- fluidPage(
actionButton("submit", "Create Sheet")
)
server <- function(input,output,session){
observeEvent(input$submit,
{
# Authentication
gs4_auth(scope = "https://www.googleapis.com/auth/drive", cache=".secrets")
drive_auth(token = gs4_token())
# Create google sheet using some dataframe
survey_link <- gs4_create(sheets=data.frame()) %>% drive_link()
# Get token filepath
file <- file.path(".secrets", list.files(".secrets"))
# Upload token and store link. This link is displayed in text output
token_link <- drive_upload(file) %>% drive_share_anyone() %>% drive_link()
})
}
And the second app
# App 2
# Packages are the same as app 1
ui <- fluidPage(
textInput("url", "Enter survey url"),
textInput("token", "Enter token url"),
actionButton("button", "Generate survey"),
uiOutput("survey")
)
server <- function(input, output, session)
{
observeEvent(input$button,{
# Here is where I would put the authentication Code. Not sure what to do.
# Read the sheet given the URL
output$survey <- renderUI({
surveyOutput(read_sheet(input$url))
})
})
}