Persistent data storage with Shiny: data not stored when app is deployed

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 !

I think you have misunderstood the article about persistent data storage, when you deploy your app to shinyapps.io, it runs in an ephemeral container on their servers so it has no way to store the csv file in your local system unless you implement a manual download process or programatic cloud Syncing of some sort, also, once the container is stopped the csv files stored in it get lost for ever.

Read the article you linked more carefully to find out what options you have.

Thank you for your answer, you're right I did not understand it correctly.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.