0

I'm trying to build an app that makes a data.frame from 3 inputs, shows it in the main panel, and saves the final data.frame into a GoogleSheet in the end. I used this Table as output based on user input in R shiny to complete the first step, but when I try to save it I'm getting this error:
Auto-refreshing stale OAuth token.
√ Writing to Axie.
√ Appending 2 rows to Principal.
Warning: Error in : Don't know how to make an instance of from something of class <integer/shinyActionButtonValue>.
[No stack trace available]

Here's my code:

library(shiny)
library(tidyverse)
library(googlesheets4)
library(DT)

# Authorize googlesheets4
gs4_auth(
  cache = ".secrets",
  email = "my email"
)

# GoogleSheets ------------------------------------------------------

Linksheet <- "linkGoogleSheet"
sheet <- "Principal"

UI = fluidPage(
      headerPanel('Axie'),
      sidebarPanel(
        dateInput('date', "Choose today's date:", value = NULL, min = NULL, max = NULL,
                   format = "yyyy-mm-dd", startview = "month", weekstart = 0,
                   language = "en", width = NULL)
        ,numericInput("slp_rodada", label = h3("Submit SLP"), value = NA)
        ,numericInput("rank_rodada", label = h3("Submit Rank"), value = NA)
        ,actionButton("action", label = "Submit Scores") )
      ,mainPanel(
        DTOutput("diary_table")
        ,actionButton("save", label = "Save data")
              ))
     
SERVER = function(input, output, session) {     
           
      tableValues <- reactiveValues(df = data.frame(Date = as.Date(as.character()),
                                                    Number_game = as.numeric(),
                                                    SLP = as.numeric(),
                                                    Rank = as.numeric(),
                                                    check.names = FALSE))
      
      observeEvent(input$action, {
        
        temp <- tableValues$m
        
        newRow <- data.frame(Date = input$date,
                             Number_game = input$action,
                             SLP = input$slp_rodada,
                             Rank = input$rank_rodada)
        
        
        if(!is.null(temp)) {
          
          if(isolate(input$date) < temp[nrow(temp), 1]) {
            temp <- rbind(temp, newRow)
            temp <- dplyr::arrange(temp, Date)
          } else {
            temp <- rbind(temp, newRow)
          }
        } else {
          temp <- rbind(temp, newRow)
        }
        
        tableValues$m <- temp
        
      })
      
      
      output$diary_table <- DT::renderDataTable({ tableValues$m })
      
      observeEvent(input$save,{
        
        # Linksheet %>% sheet_append(data = newRow ,sheet =  sheet )
        Linksheet %>% sheet_append(data = isolate(tableValues$m) ,sheet =  sheet )

        # reinitiating the page
        tableValues <- reactiveValues(df = data.frame(Date = as.Date(as.character()),
                                                         Number_game = as.numeric(),
                                                         SLP = as.numeric(),
                                                         Rank = as.numeric(),
                                                         check.names = FALSE))

           updateNumericInput(session, inputId = "slp_rodada",  label = h3("Submit SLP"), value = NA)
           updateNumericInput(session,"rank_rodada", label = h3("Submit Rank"), value = NA)
           updateActionButton(session, "action", label = "Submit Scores")

      })
    }
  
shinyApp(
  ui = UI,
  server = SERVER
)

enter image description here

0 Answers0