I have a working Shiny app that is contained in a flexdashboard. I have not been able to figure out the best way to automatically refresh the data connection every 15 minutes.
I'm using a special function to read the csv file (skipping 3 rows), so I'm not sure how to proceed.
---
title: "Dashboard"
output:
flexdashboard::flex_dashboard:
orientation: rows
veritcal_layout: scroll
source_code: embed
runtime: shiny
---
Row {data-height=650}
-------------------------------------
### DataGraph 1
````{r global, include=FALSE}
library(flexdashboard)
library(readr)
library(lubridate)
ez.read = function(file, ..., skip.rows=NULL, tolower=FALSE){
if (!is.null(skip.rows)) {
tmp = readLines(file)
tmp = tmp[-(skip.rows)]
tmpFile = tempfile()
on.exit(unlink(tmpFile))
writeLines(tmp,tmpFile)
file = tmpFile
}
result = read.csv(file, ...)
if (tolower) names(result) = tolower(names(result))
return(result)
}
data <- ez.read("last8hours.csv", skip.rows = 2:3, tolower = T))
data$x <- as.POSIXct(data$x, format= "%d-%b-%Y %H:%M")
datah <- ez.read("last24.csv", skip.rows = 2:3, tolower = T)
datah$x <- as.POSIXct(datah$x, format= "%d-%b-%Y %H:%M")
````
I would like to either detect file changes or schedule an update on the data and datah connections every 15 minutes. What is the best way to achieve this and how might it look with the function I'm using to read the csv files?