Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Time range input with Hour level detail in shiny

Tags:

r

shiny

This is a simple question. I want to create in my app an input similar to dateRangeInput, however besides YYY-MM-DD I also want for it to let me pick the the exact hour, minutes and second from the range, is there any method in shiny like this? I can't seem to find it on google.

I could just make a text input but I like the interface provided by dateRangeInput

like image 415
user697110 Avatar asked Aug 09 '16 11:08

user697110


1 Answers

You can set the variable type to POSIXct, here's an example:

library(shiny)

# ui.R

ui <- shinyUI(fluidPage(
  title = 'Initial run of time range update breaks sliderInput',
fluidRow(
column(width = 12, 
       sliderInput("timeRange", label = "Time range",
                   min = as.POSIXct("2011-06-04 12:00:00"),
                   max = as.POSIXct("2011-08-10 14:00:00"),
                   value = c(as.POSIXct("2011-06-04 12:00:00"),
                             as.POSIXct("2011-08-10 14:00:00"))),
       actionButton("update", "Update range")

)
)))

server <- shinyServer(function(input, output, session) {
       output$from <- renderText(input$timeRange[1]);
       output$to <- renderText(input$timeRange[2]);
       observe({
          input$update;
          updateSliderInput(session, "timeRange", value = 
          c(as.POSIXct("2011-06-14 
          12:00:00"), as.POSIXct("2011-08-01 14:00:00")));
})
})

runApp(list(ui = ui,server = server))

Output:

enter image description here

like image 93
Vitor Quix Avatar answered Oct 12 '22 20:10

Vitor Quix