R 中的流数据可视化

Streaming data visualization in R

它看起来很简单,但我正在努力解决它。基本上我试图可视化(绘制)每两秒出现一次的模拟流数据,即实时连续的绘图。

我看过 Microsoft Azure(但我没有昂贵的订阅)。我也看到了动画包,但它必须在渲染显示之前读入所有数据。有没有办法在 R 中实现这一点(或者 python)? 这是我到目前为止在 R 中所做的:

    #simulate some sensor data
time <- seq(1,200,2)
sensor <- runif(100,1,100)
timedf <- data.frame(cbind(time,sensor))
timedf$time <- as.POSIXct(timedf$time,origin = "2016-05-05")

plot(timedf$time,timedf$sensor,type = "l")

#I want to visualize or plot the data continously every 2 seconds
#sleep function
mysleep <- function(x)
{
  p1 <- proc.time()
  Sys.sleep(x)
  proc.time() - p1 
}

for(i in 1:nrow(timedf)){ 
  mysleep(2)
  print(timedf[i,])
  plot(timedf[i,]$time,timedf[i,]$sensor,type = "l")
  par(new=FALSE)
}[![some sensor data][1]][1]

下面是使用 nodejs 的演示:

#clone the nodejs plotly github directory
git clone https://github.com/plotly/plotly-nodejs.git

使用您的 API credentials 编辑 examples/config.json 文件,然后 运行 提供的演示之一(在本例中;signal-stream.js

node signal-stream.js

这将以以下形式输出 JSON 字符串:

{ streamstatus: 'All Streams Go!', 
  url: 'https://plot.ly/~voxnonecho/194',
  message: '',
  warning: '',
  filename: 'streamSimpleSensor',
  error: '' }

然后只需按照URL提供的: