I am deploying on shiny server pro. Below is the sample. I am trying to append the csv file if it exists.
library(shiny)
if (interactive()) {
# Open this application in multiple browsers, then close the browsers.
shinyApp(
ui = basicPage("onStop demo"),
server = function(input, output, session) {
# Sys.sleep(10)
# print(Sys.time())
# onStop(function() print(Sys.time()))
},
onStart = function() {
user_name <- Sys.getenv("RSTUDIO_USER_IDENTITY")
# Start_date <- format(Sys.time(), "%d-%m-%Y")
Start_time <- format(Sys.time(), "%d-%m-%Y %H:%M:%S")
onStop(function() {
# End_date <- format(Sys.time(), "%d-%m-%Y")
End_time <- format(Sys.time(), "%d-%m-%Y %H:%M:%S")
log_data <- cbind(user_name,Start_time,End_time,
difftime(Start_time,End_time,units = "secs"))
# write.csv(log_data,"log_data.csv")
if (file.exists("log_data.csv")) {
write.table(log_data,
file="log_data.csv",
append = T,
sep=',',
row.names=T,
col.names=F )
} else {
write.csv(log_data,"log_data.csv")
}
})
}
)
}