Reactivity not operating fast enough for quick plotting


#1

Hello,

I am plotting a graph and attempting to have it re-plot at least every 100ms as that is how often the data file (logfile1.txt) gets new data. I have tried so many different approaches and it is yet to have any difference on how fast the plot updates. Currently the plot will update every 1000ms at the fastest. Any and all ideas are much appreciated.
Some attempts include:
Using invalidateLater
Turning the plot into a function and returning it
Swapping out reactiveTimer to 10000ms creates a longer delay (as expected for testing purposes)
Many attempts at reactiveFileReader but inevitably failed, I am thinking this way might be promising since you can specify the time in here instead, but yet to get a working version in there.

  
  autoInvalidate <- reactiveTimer(20)
  

output$plot1 <- renderPlot({
autoInvalidate
  tryCatch(chuck1 <- read.csv("logfile1.txt",header=FALSE), error=function(e) NULL)
  if(exists("chuck1")==FALSE){
    chuck1 <- read.csv("logfile1.txt",header=FALSE)
    plot(chuck1$V1, chuck1$v1, type = "o", xlim = c(0,100), ylim = c(0,5), xaxt='n', ylab = "G Force", xlab = "Time")
  }else{
  chuck1 <- na.omit(chuck1)
  if(!is.null(chuck1) && nrow(chuck1) != 0)
  {
    rownumber <- 1:nrow(chuck1)
    rownumber2 <- cbind(rownumber, chuck1[,2])
    result <- plot(rownumber2[,1],rownumber2[,2], type="o", xlim = c(0,100), ylim = c(0,5), xaxt='n', ylab = "G Force", xlab = "Time")
  }}})

Sample data (Time, Accelerometer):

4730.253,1.005132
4730.459,1.010551
4730.665,1.003719
4730.871,0.9959942
4731.078,0.9960471
4731.285,1.008995
4731.491,1.009463
4731.697,1.008489
4731.902,1.007614
4732.108,1.009856
4732.388,1.009964
4732.594,1.009399
4732.799,1.007242
4733.005,1.010573
4733.21,1.014938
4733.415,1.006392
4733.62,0.9997256
4733.825,1.009492
4734.031,1.006804
4734.236,1.009976
4734.441,1.009453
4734.646,1.010463
4734.852,1.004576
4735.057,1.007245
4735.261,1.008799
4735.467,1.008779
4735.673,1.00844
4735.878,1.009035
4736.083,1.007576

#2

Are you re-reading the whole CSV each time it changes? Why not read the last row... You'd save time that way.


#3

I haven't looked at your example in detail but RStudio IDE has a profile tab to check graphically which part of your code is taking the longest time