2017-05-08 10 views
0

가정하자 나는 다음과 같은 응용 프로그램이 있습니다 (최소 재현 예)반짝이 관찰자와 dygraph에서 줌을 유지

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 ​​()에 추가하면 다이 그래프가 다시 렌더링되고 축소됩니다. 확대/축소를 유지할 수있는 방법이 있습니까?

답변

1

샤우트 아웃이 저를 도와 Github에서에 @jjallaire합니다 : https://github.com/rstudio/dygraphs/issues/162 기본적으로

, 당신이해야 할 모든과 같이 retainDateWindow라는 dyOptions에서 추가 인수를 추가한다 :

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