I am having trouble saving the output data in an Excel file using shinyapps.io.

Shiny can run locally and is able to save output data in Excel, but when I publish the output data using shinyapps.io, I am unable to save it in an Excel file.

Below code works well locally but not on shinyapps
observeEvent(input$publish, {
current_results <- results()
file_path <- "results.xlsx"

# Load existing data if the file exists
if (file.exists(file_path)) {
  existing_data <- read.xlsx(file_path)
  updated_data <- rbind(existing_data, current_results)
} else {
  updated_data <- current_results
}

# Save the updated data to the Excel file
write.xlsx(updated_data, file = file_path, overwrite = TRUE)

output$results_table <- renderTable({
  updated_data
}, rownames = TRUE)

})

Hi!

Sorry to hear you're having trouble! When you say the code doesn't work on shinyapps.io, could you describe what is happening? do you see any error messages?

Could you create a minimal reprex shiny app that someone else could try out to help debug?

Keep in mind that shinyapps.io application storage is not persistent.

I think what you are going to want to do is use a file input widget to upload the existing data and a file download widget to let the user download the updated data.

The code works on shinyapps.io without any errors. I have a button called "publish" in the script. When I click "publish," I am able to save data when I run the script locally (R studio). However, after deploying it in shinyapps.io, even when I click the "publish" button, the output data is not saved in the Excel file located in the directory. I hope its clear now.