r语言 - 使用闪亮观察者保留对齐图的放大



假设我有以下应用程序:(最小可重现的示例(

library(shiny)
library(dygraphs)
library(xts)
runApp(
  list(
    ui = 
      mainPanel(
        tableOutput(outputId="dataTable")
        ,dygraphOutput("testGraph")
      ),
    server = function(input, output, session) {
      myReact <- reactiveValues(df = data.frame(time_stamp = as.integer(Sys.time()), foo = rnorm(1)))
      readTimestamp <- function() Sys.time()
      readValue <- function(){
        data.frame(time_stamp = as.integer(Sys.time()), foo = rnorm(1))
      }
      data <- reactivePoll(5*1000, session, readTimestamp, readValue)  # Add to data frame every x seconds 
      observe({
        myReact$df <- rbind(data(), isolate(myReact$df))
      })
      output$dataTable <- renderTable({
        head(myReact$df, 10)  
      })
      output$testGraph <- renderDygraph({
        x <- myReact$df
        x.ts <- xts(x = x[,2], order.by = as.POSIXct(x[[1]], origin = "1970-01-01"))
        dygraph(x.ts, main = "This should work")
      })
    })
)

我遇到的问题是:当用户放大时,reactivePoll(( 执行(在本例中为每 5 秒一次(,从而附加到 reactiveValues((,dygraph 会重新渲染并缩小。有没有办法保留缩放?

Github 上向@jjallaire大喊大叫,以帮助我解决这个问题:https://github.com/rstudio/dygraphs/issues/162

基本上,您需要做的就是在dyOptions中添加一个名为retainDateWindow的额外参数,如下所示:

dygraph(x.ts, main = "This should work") %>%
   dyOptions(retainDateWindow = TRUE)

最新更新