【问题标题】:How to update values in Shiny without flickering?如何在 Shiny 中更新值而不闪烁?
【发布时间】:2018-01-19 17:27:57
【问题描述】:

我每秒都在更新一个从 sql 数据库读取的文本输出,它只需要一些时间。在仪表板中,我只想看看输出如何在没有花哨的动画/闪烁的情况下发生变化。是否可以删除动画并在等待更新时仅显示文本?

这是一些代码示例,您可以在其中看到更新的闪烁:

# ui.R
library(shiny)

shinyUI(fluidPage(

  # App title ----
  titlePanel("Title"),

  # Sidebar layout with input and output definitions ----
  sidebarLayout(

    # Sidebar panel for inputs ----
    sidebarPanel(),

    # Main panel for displaying outputs ----
    mainPanel(
      # Output: Data file ----
      # Output: Tabset w/ plot, summary, and table ----
      tabsetPanel(type = "tabs",
                  tabPanel("Main", 
                           textOutput("foo"))
      )

    )
  )
)
)

# server.R
library(shiny)

check_for_update <- function() {
  Sys.time()
}
get_data <- function() {
  df <- data.frame(replicate(20000,sample(0:1000,rep=TRUE)))
}


shinyServer(
  function(input, output, session) {
    # checks for new data every 1 seconds
    data <- reactivePoll(50, session,
                         checkFunc = check_for_update,
                         valueFunc = get_data)

    # the outputs will only be refreshed in case the data changed
    output$foo <- renderText({
      df <- data()
      df[[2]]
    })
  }
)

提前致谢!

【问题讨论】:

  • 你能做一个minimalreproducible的例子吗?
  • 更新了问题!
  • 快到了,我们无法测试您的代码。你能让它重现吗?
  • 成功了!你能把它作为答案发布,这样我就可以给你和乔的功劳了吗?

标签: r shiny


【解决方案1】:

某些 html 诱导的情节无法避免闪烁/刷新,例如通过传单。

您可以将闪亮应用的不透明度调整为 1,以发出不闪烁的错觉,但它仅适用于某些非 html 对象。请参阅此linkJoe Cheng​​strong> 的回答。一年半前我从来没能解决这个问题。

例如,可以通过 grob 对象的动画来消除闪烁。尝试使用带有 ggplot 折线图的动画来解决 Joe 的解决方案。

【讨论】:

    猜你喜欢
    • 2017-01-29
    • 1970-01-01
    • 2011-10-02
    • 2012-02-06
    • 2014-08-08
    • 2013-01-02
    • 1970-01-01
    • 2017-05-11
    • 2016-09-25
    相关资源
    最近更新 更多