2

I'm working on building a Shiny App for work and currently have it up and running using a dateRangeInput() for pulling data. I'm looking for an alternative to this though so that users can be more specific with the range, so they can also choose time as an input as well. So basically my input looks like the following:

dateRangeInput('dates', 'Timeframe To Pull')

and is referenced in my server as

starddate = input$dates[1]
enddate = input$dates[2]

But this is restrictive, as some of their data cannot overlap and will switch profiles in the middle of the day (unscheduled). So having an input for datetime range rather than just date range would be huge. I know that there's a package called shinyTime out there, but it only works with times, not datetimes. So I'm looking to see if there's something cleaner out there.

Thanks in advance for any help!

obewanjacobi
  • 458
  • 2
  • 12
  • 1
    https://stackoverflow.com/a/38440491/3330437 The option of using numeric datetimes and formatting it yourself is what I would probably do. – Brian Jul 05 '22 at 19:36

1 Answers1

1

I've just done a package for you :-)

remotes::install_github("stla/DateTimeRangePicker")

The following example is included in the doc.

library(DateTimeRangePicker)
library(shiny)

ui <- fluidPage(
  br(),
  sidebarLayout(
    sidebarPanel(
      width = 5,
      tags$fieldset(
        tags$legend("Click to change time"),
        dtrpickerInput(
          "dtrpicker",
          style = paste0(
            "background-color: chartreuse; ",
            "box-shadow: 0 30px 40px 0 rgba(16, 36, 94, 0.2);"
          )
        )
      )
    ),
    mainPanel(
      width = 7,
      verbatimTextOutput("dtrpicker")
    )
  )
)

server <- function(input, output){
  output[["dtrpicker"]] <- renderPrint({
    input[["dtrpicker"]]
  })
}

shinyApp(ui, server)

enter image description here

Note that there's no clock for the second date. Perhaps it's a bug of the JavaScript library, I don't know.

Stéphane Laurent
  • 75,186
  • 15
  • 119
  • 225
  • Wow that's awesome. Super cool that you were able to put this together in such a short time! Thanks! – obewanjacobi Jul 07 '22 at 14:33
  • So I've run into an error, when I try to run the above example code I get the following errors: Warning: Error in : CCTZ: Invalid timezone of the input vector: "" [No stack trace available] Error : CCTZ: Invalid timezone of the input vector: "" Warning: Error in : CCTZ: Invalid timezone of the input vector: "" [No stack trace available] Error : CCTZ: Invalid timezone of the input vector: "" Any idea where these might be coming from? I've looked through the code and haven't found any reference to CCTZ. – obewanjacobi Jul 07 '22 at 16:43