r - 使用 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()
})
}
)
如果有人可以帮助我,那就太棒了!提前致谢
解决方案
推荐阅读
- keyboard - Logitecth MX Keys 键盘上的查找按钮的用途是什么?
- flutter - 颤振本地通知清单插件
- node.js - 如何将从 API 返回的 png 图像存储到 mongodb
- android - ANR - 输入调度超时 - Android 11
- javascript - 数组中最大连续数字项+1差
- flutter - 在颤振中,如何在已安装的本机应用程序中播放流式视频
- android - 为什么当我从我的应用程序中删除视频文件时会出现这种情况
- xcode - Alamofire/Postman [错误] 此服务器的证书无效(Xcode)
- linux - 在编写 bash 脚本时给用户输入
- cmd - PuTTY:如何自动以 sudo 身份登录,然后传递我的密码