Hi! I am working on a Shiny app that should store data locally in separate csv files. I followed the procedure for Persistent data storage in Shiny apps. The files are stored properly when I run my app locally, but not when I deploy the app with rsconnect. When the app is deployed, I can navigate it without encountering any problems, but no csv gets saved on my machine.
I am wondering if the issue could be related to the following warning message that I receive when deploying (discussed here too):
Error detecting locale: Error in read.table(file = file, header = header, sep = sep, quote = quote, : incomplete final line found by readTableHeader on 'raw'
(Using default: en_US)
Here's the code for my app (it requires a 'responses' folder to be placed in the same working directory as the app):
library(shiny)
library(shinydashboard)
#>
#> Attachement du package : 'shinydashboard'
#> The following object is masked from 'package:graphics':
#>
#> box
outputDir <- "responses"
# Define the fields we want to save from the form
fields <- c("v1", "v2")
# Define functions
saveData <- function(data) {
data <- t(data)
fileName <- sprintf("%s+%s.csv", as.integer(Sys.time()), digest::digest(data)) # define file name
write.csv( # store data in csv
x = data,
file = file.path(outputDir, fileName),
row.names = FALSE, quote = T, fileEncoding = "UTF-8"
)
}
# Define ui and server
ui = dashboardPage(
skin = "black",
dashboardHeader(title = "Survey"),
dashboardSidebar(
sidebarMenu(
menuItem("Home", tabName = "home", icon = icon("home")))
),
dashboardBody(
tabItems(
tabItem(tabName = "home",
fluidRow(
box(
radioButtons("v1",
h3("Question 1"),
choices = list("a", "a", "c"),
selected = NULL),
checkboxGroupInput("v2",
h3("Question 2"),
choices = c("a", "b", "c"),
selected = NULL),
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())
})
}
shinyApp(ui = ui, server = server)
Thanks in advance !