I'm writing a simple shiny app that generates a table of random numbers every 5 seconds. I first insert dummy values to the table then edit the table within an observe()
loop using replaceData()
. 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. It appears that all subsequent calls to replaceData()
within the observe()
function are ignored.
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
shiny: 1.2.0
DT: 0.5
Replace
testTableProxy <- dataTableProxy(session$ns('testTable'))
with
testTableProxy <- dataTableProxy('testTable')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.