简体   繁体   English

DT :: replaceData()仅在observe()中执行一次

[英]DT::replaceData() only executing once in observe()

I'm writing a simple shiny app that generates a table of random numbers every 5 seconds. 我正在编写一个简单的闪亮应用程序,该应用程序每5秒生成一个随机数表。 I first insert dummy values to the table then edit the table within an observe() loop using replaceData() . 我首先将虚拟值插入表中,然后使用replaceData()observe()循环中编辑表。 When I run the app I see that the table gets populated with random numbers (which must come from the replaceData() call) but the table does not get re-populated every 5 seconds after that. 当我运行该应用程序时,我看到该表填充了随机数(必须来自replaceData()调用),但是replaceData()并没有每隔5秒重新填充该表。 It appears that all subsequent calls to replaceData() within the observe() function are ignored. 看来, observe()函数中对replaceData()所有后续调用都将被忽略。

Does anyone have any suggestions/ideas as to what might be causing this? 是否有人对造成此问题有任何建议/想法?

app.R 应用程序

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)

module.R 模块

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"))
}

Software specs: 软件规格:

R: 3.5.2 R:3.5.2

shiny: 1.2.0 闪亮的:1.2.0

DT: 0.5 DT:0.5

Replace 更换

  testTableProxy <- dataTableProxy(session$ns('testTable'))

with

  testTableProxy <- dataTableProxy('testTable')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM