Best way to automatically update data connection on schedule or on changes?

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?

I think you may be interested by this function reactiveFileReader
http://shiny.rstudio.com/reference/shiny/1.3.2/reactiveFileReader.html

For more custom source, you have also reactivePoll
http://shiny.rstudio.com/reference/shiny/1.3.2/reactivePoll.html

or reactiveTimer for invalidation of reactive
http://shiny.rstudio.com/reference/shiny/1.3.2/reactiveTimer.html

You'll find example in

Hope it helps

1 Like

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