admin管理员组文章数量:1287668
I'm working on a shiny app that includes (among other things) a time series animation with sliderInput
for the dates. I want to show the time series data as a line graph slowly showing over time. The animation runs, but becomes choppy, since the full plot gets re-drawn every time. I'm certain I've seen a way to smooth it out at some point, but haven't been able to find it again. Ideally, the app wouldn't need to redraw the entire plot at every time stamp.
library(dplyr)
library(ggplot2)
library(shiny)
data <- expand.grid(Date = seq(as.Date("2001-01-01"), as.Date("2001-12-31"), "1 day"),
Var = c("Variable1", "Variable2"), Group = c("a", "b")) %>%
mutate(Val = rnorm(n(), 0, 1),
Val = ifelse(Group == "b", Val * 2, Val))
server <- function(input, output, session) {
output$Plot <- renderPlot({
req(input$DateSlider)
sub <- data %>%
filter(Date <= input$DateSlider)
ggplot(sub) +
geom_line(aes(x = Date, y = Val, group = Group, colour = Group)) +
facet_wrap(~ Var, scales = "free_y", ncol = 1) +
scale_x_date("Date", limits = range(data$Date))
})
}
ui <- fluidPage(
fluidRow(
column(7, plotOutput("Plot", width = "100%")),
column(3, sliderInput("DateSlider", "Animation period",
min = min(data$Date), max = max(data$Date), step = 1, ## by day
value = min(data$Date), animate = animationOptions(loop = FALSE, interval = 10[![enter image description here][1]][1]0)))))
shinyApp(ui, server)
本文标签: rAnimated time series in shinychoppyStack Overflow
版权声明:本文标题:r - Animated time series in shiny - choppy - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741265313a2368352.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论