【问题标题】:Adding rows with encoding to a Google Sheet R package googlesheets将带有编码的行添加到 Google Sheet R 包 googlesheets
【发布时间】:2016-06-07 05:14:06
【问题描述】:

我正在使用这个神奇的软件包,以便能够通过我闪亮的应用程序读取和上传数据。它工作正常,但是当我在工作表中添加一行时,它不会与服务器保持相同的编码,也不会像前几行中的数据那样表现。我手动输入的西班牙名称是可以的,但是当我使用该应用程序加载数据时,表格中的特殊拉丁字符 (UTF-8) 会被替换。 该数据在以下会话中无法被应用识别。

library(googlesheets)

table <- "Reportes"

saveData <- function(data) {
  # Grab the Google Sheet
  sheet <- gs_title(table)
  # Add the data as a new row
  gs_add_row(sheet, input = data)
}

loadData <- function() {
   # Grab the Google Sheet
   sheet <- gs_title(table)
   # Read the data
   gs_read_csv(sheet)
}

然后,我使用 UI 中的按钮和 SERVER 中的观察者来加载数据...

  observeEvent(input$enviar, {
     exit <- input$enviar
     if (exit==1){

      addData <- c( as.character(input$fecha),
                   as.character(input$local),
                   as.character(input$dpto),
                   as.character(input$estado),
                   as.character(input$fsiembra),
                   as.character(input$ref), 
                   as.character(loc$lat[loc$Departamento==input$dpto & loc$Localidad==input$local]), 
                   as.character(loc$long[loc$Departamento==input$dpto & loc$Localidad==input$local]),
                   as.character(getZafra(input$fecha)))

      saveData(addData)

      d <- loadData()

      reset('fecha')
      reset('dpto')
      reset('local')
      reset('estado')
      reset('fsiembra')
      reset('ref')
      reset('pass')

      disable('enviar')

    } 

})

请...如果有人可以提供帮助,我将非常高兴。

【问题讨论】:

    标签: r google-sheets shiny packages


    【解决方案1】:

    我发现我需要在上传之前对字符向量进行编码...

    我用过:

    Encoding(addData) = "latin1"
    saveData(addData)
    

    而且工作得很好!

    【讨论】:

      猜你喜欢
      • 2015-12-08
      • 2016-06-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多