[英]DT::replaceData() only executing once in observe()
我正在编写一个简单的闪亮应用程序,该应用程序每5秒生成一个随机数表。 我首先将虚拟值插入表中,然后使用replaceData()
在observe()
循环中编辑表。 当我运行该应用程序时,我看到该表填充了随机数(必须来自replaceData()
调用),但是replaceData()
并没有每隔5秒重新填充该表。 看来, observe()
函数中对replaceData()
所有后续调用都将被忽略。
是否有人对造成此问题有任何建议/想法?
应用程序
library(shiny)
library(DT)
library(data.table)
source("module.R")
ui <- fluidPage(
testTableUI('first')
)
server <- function(input, output, session){
callModule(testTable, 'first')
}
shinyApp(ui = ui, server = server)
模块
testTable <- function(input, output, session){
# insert dummy values into the table
dummyDT = data.table(a=1:5, b=1:5, c=1:5)
output$testTable <- renderDataTable({dummyDT})
# trigger every 5 seconds in observe() to generate a new table
invalidateTable <- reactiveTimer(5000)
testTableProxy <- dataTableProxy(session$ns('testTable'))
observe({
invalidateTable()
print('Updating table...')
a_vals <- sample(1:100, 5)
b_vals <- sample(1:100, 5)
c_vals <- sample(1:100, 5)
newDT = data.table(a=a_vals, b=b_vals, c=c_vals)
print(newDT)
# only updates table once
replaceData(testTableProxy, newDT)
})
}
testTableUI <- function(id){
ns = NS(id)
dataTableOutput(ns("testTable"))
}
软件规格:
R:3.5.2
闪亮的:1.2.0
DT:0.5
更换
testTableProxy <- dataTableProxy(session$ns('testTable'))
与
testTableProxy <- dataTableProxy('testTable')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.