【发布时间】:2022-01-09 12:42:29
【问题描述】:
我正在开发一个闪亮的应用程序,它可以流式传输数据并每秒通过 renderTable 更新 UI。当应用程序在每次更新之间呈现表格时,表格会变暗,从视觉角度来看这很烦人。有没有办法禁用这种行为?
output$table_state <- renderTable({
invalidateLater(1000)
get_table_state()
})
【问题讨论】:
我正在开发一个闪亮的应用程序,它可以流式传输数据并每秒通过 renderTable 更新 UI。当应用程序在每次更新之间呈现表格时,表格会变暗,从视觉角度来看这很烦人。有没有办法禁用这种行为?
output$table_state <- renderTable({
invalidateLater(1000)
get_table_state()
})
【问题讨论】:
如果get_table_state() 执行长时间计算,您可以尝试在renderTable() 之外执行它。注意这里使用observe。
示例应用
library(shiny)
library(tidyverse)
long_calculation <- function() {
Sys.sleep(1)
iris
}
ui <- fluidPage(
fluidRow(
column(width = 6,
tableOutput('table_slow')),
column(width = 6, tableOutput('table2')))
)
server <- function(input, output, session) {
df <- reactiveValues(x = NULL)
output$table_slow <- renderTable({
invalidateLater(1000)
long_calculation()
})
iris_no_dim <- observe({
invalidateLater(1000)
df$x <- long_calculation()})
output$table2 <- renderTable({
df$x
})
}
shinyApp(ui, server)
【讨论】: