I have been trying for days to solve this error: Warning: Error in read.table: more columns than column names. Does somebody know how to solve this? It is about local database storage and I use a csv file 'interovodb' to put the data in.
This is my script:
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()
})
}
)
If somebody could help me it would be awesome! Thanks in advance