首页 > 解决方案 > 使用 R 闪亮的本地数据库存储:read.table 中的错误:列多于列名

问题描述

几天来我一直在尝试解决这个错误:警告:read.table 中的错误:列多于列名。有人知道如何解决这个问题吗?它是关于本地数据库存储的,我使用 csv 文件“interovodb”来放入数据。

这是我的脚本:

library(shiny)
library(png)
library(shinyTime)

# Define the fields we want to save from the form
fields <- c("farm name", 'Date data entry', "Feed intake", "Water intake", "Time light on", "Time light off", "Feed phase", "Eggs per week")

# Save a response
# ---- This is one of the two functions we will change for every storage type ----
saveData <- function(data) {
  data <- t(data)
  # Create a unique file name
  Interovodatafromwebapp <- sprintf("%s_%s.csv", as.integer(Sys.time()), digest::digest(data))
  # Write the file to the local system
  write.csv(
    x = data,
    file = file.path(outputDir, 'interovodb.csv'), 
    row.names = FALSE, quote = TRUE
  )
}


# Load all previous responses
# ---- This is one of the two functions we will change for every storage type ----

outputDir <- "responses"

loadData <- function() {
  # Read all the files into a list
  files <- list.files(outputDir, full.names = TRUE)
  data <- lapply(files, read.csv, stringsAsFactors = FALSE) 
  # Concatenate all data together into one data.frame
  data <- do.call(rbind, data)
  data
}

# Shiny app with 3 fields that the user can submit data for
shinyApp(
  ui = fluidPage(
    titlePanel("Interovo Egg Data Entry For Farmers"),
    sidebarPanel(
      DT::dataTableOutput("responses", width = 10), tags$hr(),
      textInput("Farm name", 'Farm name'),
      dateInput('Date data entry', 'Date data entry'),
      numericInput("Feed intake", 'Feed intake', 0),
      numericInput("Water intake", 'Water intake', 0),
      timeInput("Time light on", "Time light on", seconds = FALSE),
      timeInput("Time light off", "Time light off", seconds = FALSE),
      textInput("Feed phase", 'Feed phase'),
      numericInput("Eggs per week", 'Eggs per week', 0),
      actionButton("submit", "Submit")),
    mainPanel(
      img(src = "Logointerovogroot.png", height = 62, width = 160),
      img(src = "WURfoto.png", height = 210, width = 280)),
  ),
  server = function(input, output, session) {
    
    # Whenever a field is filled, aggregate all form data
    formData <- reactive({
      data <- sapply(fields, function(x) input[[x]])
      data
    })
    
    # When the Submit button is clicked, save the form data
    observeEvent(input$submit, {
      saveData(formData())
    })
    
    # Show the previous responses
    # (update with current response when Submit is clicked)
    output$responses <- DT::renderDataTable({
      input$submit
      loadData()
    })     
  }
)

如果有人可以帮助我,那就太棒了!提前致谢

标签: rdatabaseshinystoragelocal

解决方案


推荐阅读