hey!
I have such a problem with a code. Actually it works and I can save every data I need. However, I have to do html file and it has error.
To be honest, I even don't understand what is wrong.
saveData <- function(data) {
data <- as.data.frame(t(data))
if (exists("responses")) {
responses <<- rbind(responses, data)
} else {
responses <<- data
}
}
loadData <- function() {
if (exists("responses")) {
responses
}
}
column = c('name_of_book', 'id', 'id_of_book', 'grade_of_user', 'avg_rating', 'not_exist')
# Define the fields we want to save from the form
fields <- c("user_id", "title", "book_id", "rating", "average_rating")
# Shiny app with 3 fields that the user can submit data for
shinyApp(
ui = fluidPage(
DT::dataTableOutput("responses", width = 500), tags$hr(),
selectInput("user_id", "Column contains id of users:",
column),
selectInput("title","Column contains name/ title of a book:",
column),
selectInput("book_id", "Column contains id of books:",
column),
selectInput("rating", "Column contains user reviews grades:",
column),
selectInput("average_rating:","Column contains average rating:",
column),
actionButton("submit","Submit")
),
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()
})
}
)