【发布时间】:2016-12-20 16:52:47
【问题描述】:
我正在做一个闪亮的小应用程序,它只有一个 ggplot 每隔几秒更新一次。它有效,但闪烁有点烦人。我想知道是否有人知道如何平滑它。示例:
library(shiny)
library(ggplot2)
server <- shinyServer(function(input, output, session) {
output$showplot <- renderPlot({
grid <- expand.grid(1:3,1:3)
nums <- rbinom(9,1,0.5)
g <- ggplot(grid,aes(Var1,Var2)) +
geom_tile(aes(fill = nums),colour="black") +
guides(fill = FALSE) +
theme(axis.title.x=element_blank(), axis.text.x=element_blank(), axis.ticks.x=element_blank()) +
theme(axis.title.y=element_blank(), axis.text.y=element_blank(), axis.ticks.y=element_blank()) +
theme(aspect.ratio=1)
print(g)
invalidateLater(1000,session)
})
})
ui <- shinyUI(fluidPage(
sidebarLayout(
sidebarPanel(
),
mainPanel(
h5("Plot blinking"),
plotOutput("showplot")
)
)
))
runApp(list(ui = ui, server = server))
我应该补充一点,在寻找类似问题时,提供的解决方案是添加
tags$style(type="text/css",
".recalculating {opacity: 1.0;}" ),
作为 FluidPage 中的第一项。这似乎不适用于我的情况。
【问题讨论】:
-
您使用的是哪种操作系统和网络浏览器?我在 RStudio 0.99.491、Chrome 52.0.2743.116 或 Firefox ESR 45.3.0 的 Debian 8 机器上的图中看不到任何“闪烁”。 (R 3.31,ggplot2_2.2.1,闪亮_0.13.0)
-
啊,我没想到。 Windows 10、Firefox 48.0、ggplot2_2.1.0 shiny_0.12.2、R 版本 3.2.2。它在 Firefox 中闪烁,但在 Chrome 52.0.2743.116 中不闪烁。嗯