我在创建数据表和显示数据时之间存在竞争条件。有没有办法确保数据表在显示之前存在。 流程是
从reactiveValues List of List
显示此新数据
library(shiny)
library(data.table)
library(foreach)
library(DT)
ui <- fluidPage(DT::dataTableOutput("table"))
server <- function(input, output, session) {
values <- reactiveValues()
# Adding lists dynamically
values[["A"]] <- list(info = 1, data = data.table(i = 1, j = 2))
values[["B"]] <- list(info = 10, data = data.table(i = 10, j = 20))
observe({
# Update data everytime new elements are added to values
# This is just adding all data.tables as rows to one data.table
data <- rbindlist(foreach(list = reactiveValuesToList(values)) %do% list$data)
})
output$table <- DT::renderDataTable(data)
}
shinyApp(ui, server)
数据在observe函数内创建,然后使用DT :: renderDataTable
进行渲染答案 0 :(得分:1)
data
也应该是被动的,
observe({
values$data <- rbindlist(foreach(list = reactiveValuesToList(values)) %do% list$data)
})
output$table <- DT::renderDataTable(values$data)