我每秒都会更新一个文本输出,从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]]
})
}
)
提前致谢!
答案 0 :(得分:1)
通过一些html诱导的图,例如通过传单,不能避免闪烁/刷新。
您可以将闪亮应用的不透明度调整为1,以释放它不会闪烁的错觉,但它只适用于某些非html对象。请参阅此link以及 Joe Cheng 的答案。一年半前我从未能解决这个问题。
例如,可以使用grob对象的动画删除闪烁。尝试使用带有ggplot线图的动画的Joe解决方案。