如何每隔一定时间重新读取数据

时间:2019-07-12 11:58:43

标签: r shiny reactive-programming

我正在Shiny中创建一个程序,但遇到以下问题:我的数据文件每分钟都会自动更改,并且我想显示该数据文件中的图等信息。如何使应用程序每分钟自动重新读取数据帧?我的问题是我必须使用我创建的函数来读取数据,所以我不会使用read.tableread.csv之类的函数来读取它们。

我将尝试提供我的代码示例:

ui <- dashboardPage(
dashboardBody(
selectInput("estprediction" , label = "Est" , choices = c("A1" , "A2" , "A3"  , "A4" , "A5" , "A6" , "A7"),selectize = TRUE)),
plotOutput(outputId = "predictionplot"))
)
server <- function(input, output) {
data1 <- readweirddata("A1")
data2 <- readweirddata("A2")
...
data7 <- readweirddata("A7")
  fecha_min <- as.POSIXct(mutate(data1,Date = paste(Year, Month, Day, Hour, Min, sep = "-"))$Date,format = "%Y-%m-%d-%H-%M") 

estpred <- reactiveValues(data=data1)
observeEvent(input$estprediction, {
    if (input$estprediction== "A1"){estpred$data = data1}
    if (input$estprediction== "A2"){estpred$data = data2}
    if (input$estprediction== "A3"){estpred$data = data3}
    if (input$estprediction== "A4"){estpred$data = data4}
    if (input$estprediction== "A5"){estpred$data = data5}
    if (input$estprediction== "A6"){estpred$data = data6}
    if (input$estprediction== "A7"){estpred$data = data7}
  })

 output$predictionplot <- renderPlot({
    df <- data.frame(fecha_min,estpred$data[c(1,2,4)])
    ggplot(df, aes(fecha_min)) + 
    geom_line(size=1,aes(y = estpred$data[1], colour = paste("Var1", "min(μg/m3)")))} +
geom_line(size=1,aes(y = estpred$data[2], colour = paste("Var1", "min(μg/m3)")))} +
geom_line(size=1,aes(y = estpred$data[4], colour = paste("Var1", "min(μg/m3)")))} 

  })

}



当某人运行该程序时,它将读取当前数据,但是每分钟这些数据帧都会改变,但是shinny应用程序不会再次读取它们。当我不得不使用readweirddata函数时,如何使应用程序每分钟重新读取数据文件?
任何帮助将不胜感激。

0 个答案:

没有答案