I have an R Shiny app using flexdashboard that I update a few times a week at work. I've scheduled it to automatically update each weekday, and I thought it would be nice to add a timestamp for when it was redeployed. This is where I'm running into problems...
This is the code I currently have in my .Rmd file:
date: 'Updated: `r format(as.POSIXct(format(Sys.time(), tz = "America/Denver")), "%b %d %I:%M %p")`'
It outputs what I would expect, which is something like "Mar 09 4:00 PM".
However, since I'm using Sys.time(), I realized that my shiny dashboard is only outputting the timestamp of when the dashboard is loaded, and not when it was actually updated. I find the same problem when using similar functions, such as lubridate::now()
.
Is there any way I can automate adding a static timestamp to an R Shiny app or flexdashboard header at the time of deployment?
You can use the modified date of your app's data:
format(as.POSIXct(format(file.info('.//data.rdata')$mtime, tz = "America/Denver")), "%b %d %I:%M %p")
Alternatively, as part of your deploy script you could create a .txt or .rdata file with the appropriate date.