1

I need to build an app where time input in %T format has to modify time range visible on chart. I am using shiny and dygraph, and it works as stated in the documentation: one can extract dateWindow. However, changes in my system occur at a finer time scale, so I need to be able to control hours, minutes and seconds in the range selector. Is there any way to achieve that?

Here is an example: you can change the range with the dygraph range selector, and it shows hours and minutes, but when I press the button that reads the dygraph_date_window to a reactive value, only date is added. I am looking for a workaround, because I want to be able to update the time input field and (currently not in code) to update the range in the dygraph using the time input field.

library(dygraphs)
library(shiny)
library(shinyTime)

data("sample_matrix")
sample_xts<-as.xts(sample_matrix)


ui<-fluidPage(

      dygraphOutput("dygraph"),
      verbatimTextOutput("from"),
      dateInput("start_date","Start date"),
      timeInput("start_time","Start time"),
      actionButton("settime_bttn", "Set time")

)


server<-function(session, input, output) {


  #1. initialize time constraints
  timelimits<-reactiveValues(start=start(sample_xts),end=end(sample_xts))

  #2. draw dygraph with range selector
  output$dygraph <- renderDygraph({
    dygraph(sample_xts)%>% 
      dyRangeSelector(dateWindow = c(timelimits$start,timelimits$end))

  })

  #3. modify timelimits and input fields with range selector
  observeEvent( input$settime_bttn, {
    rs<-input$dygraph_date_window
    timelimits$start<-rs[[1]]
    timelimits$end<-rs[[2]]
    updateDateInput(session, "start_date", value = substr(rs[[1]],1,10))
    updateTimeInput(session, "start_time", value = rs[[1]])
  })

  output$from <- renderText({
    req(input$dygraph_date_window[[1]])
  })

}

shiny::runApp(list(ui = ui, server = server))
  • 1
    Hi, you should add a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example), it is very hard to start from scratch and to reproduce your problem just with your explanations – bretauv Jan 08 '20 at 20:40

0 Answers0