首页 > 解决方案 > 如何在 Googlesheet 中将许多闪亮的输入保存为 data.frame?

问题描述

我正在尝试构建一个应用程序,从 3 个输入生成一个 data.frame,在主面板中显示它,最后将最终的 data.frame 保存到 GoogleSheet 中。我使用此表作为基于 R 闪亮中的用户输入的输出来完成第一步,但是当我尝试保存它时,我收到了这个错误
自动刷新过时的 OAuth 令牌。
√ 写信给 Axie。
√ 向 Principal 添加 2 行。
警告:错误:不知道如何从类 <integer/shinyActionButtonValue> 中创建实例。
[没有可用的堆栈跟踪]

这是我的代码:

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
)

在此处输入图像描述

标签: rgoogle-sheetsshinyshinyappsshiny-reactivity

解决方案


推荐阅读