Having >1 Reactive Dataframes in Rshiny from GoogleSheets (solved)

88 Views Asked by At

I've been thinking about this problem for a long time and can't seem to figure it out! What I've built is a RShiny App that captures REACTIVE (real-time) data from googlesheets using the library(googlesheets4) and populate a datatable.

What Works

I am able to get my app to work by feeding it with just 1 dataframe from 1 google sheet.

 global <- reactiveValues(df = "")
    
    observe({
      if(! identical(global$df,DF())) #<- This refreshes the dataframe if different
        global$df = DF()
    })
    
    # Test Dataframe
    DF <-reactive({
      invalidateLater(60000,session=session)
      gs4_deauth()
      temp<-read_sheet("SHEETURLHERE", sheet = 'SHEETTITLE') #<- reads in 1 sheet 
      temp})

What I am Trying to Achieve

From the above, you can see that I am only able to read in 1 sheet for my entire application. I am trying to read in 2 or more sheets instead so that I can perform some transformation prior to displaying them in a datatable.

What I've tried (EDITED, the solution below works!)

global <- reactiveValues(df = "", df1 = "")

observe({
  if(! identical(global$df,DF()) | ! identical(global$df1, DF1()) 
    global$df = DF()
    global$df1 = DF1()
})

# Test Dataframe
DF <-reactive({
  invalidateLater(60000,session=session)
  gs4_deauth()
  temp<-read_sheet("SHEETURLHERE", sheet = 'SHEETTITLE') #<- reads in 1 sheet 
  temp})

DF1 <-reactive({
  invalidateLater(60000,session=session)
  gs4_deauth()
  temp<-read_sheet("SHEETURLHERE", sheet = 'SHEETTITLE') #<- reads in 1 sheet 
  temp})

Can someone please assist?

0

There are 0 best solutions below