【问题标题】:DT::replaceData() only executing once in observe()DT::replaceData() 在 observe() 中只执行一次
【发布时间】:2019-03-13 21:48:13
【问题描述】:

我正在编写一个简单的闪亮应用程序,它每 5 秒生成一个随机数表。我首先将虚拟值插入到表中,然后使用replaceData()observe() 循环内编辑表。当我运行应用程序时,我看到表格填充了随机数(必须来自replaceData() 调用),但之后表格不会每 5 秒重新填充一次。似乎在observe() 函数中对replaceData() 的所有后续调用都将被忽略。

是否有人对可能导致此问题的原因有任何建议/想法?

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)

模块.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"))
}

软件规格:

R:3.5.2

闪亮:1.2.0

DT:0.5

【问题讨论】:

    标签: r shiny dt


    【解决方案1】:

    替换

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

      testTableProxy <- dataTableProxy('testTable')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多