【发布时间】:2021-07-18 05:24:13
【问题描述】:
我已经构建了一个闪亮的应用程序,它调用 sql 表中的行,如下所示。此代码每 1 秒读取一次。我想检查是否有办法捕获每秒记录的数据。例如,当我打开应用程序时,xnew 读取为 2,下一秒为 6,第三秒为 9。我们是否可以按预期捕获
library(shiny)
library(RODBC)
ui <- fluidPage(
verbatimTextOutput("nm")
)
server <- function(input, output, session) {
x <- reactiveVal()
observe({
invalidateLater(1000,session)
xnew <- nrow(data.frame(sqlQuery(conn, "select * from ABC")))
x(c(x(), xnew))
})
output$nm <- renderPrint({
x()
})
}
shinyApp(ui, server)
预期
ColA ColB
1 2
2 6
3 9
【问题讨论】: