【问题标题】:Stop shiny renderTable from dimming when updating data更新数据时停止闪亮的渲染表变暗
【发布时间】:2022-01-09 12:42:29
【问题描述】:

我正在开发一个闪亮的应用程序,它可以流式传输数据并每秒通过 renderTable 更新 UI。当应用程序在每次更新之间呈现表格时,表格会变暗,从视觉角度来看这很烦人。有没有办法禁用这种行为?

output$table_state <- renderTable({
    invalidateLater(1000)
    get_table_state()
})

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    如果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)
    

    【讨论】:

      猜你喜欢
      • 2017-05-05
      • 2013-05-18
      • 1970-01-01
      • 2016-06-12
      • 2014-10-22
      • 1970-01-01
      • 2022-07-30
      • 2021-02-13
      • 2014-12-12
      相关资源
      最近更新 更多