UI elements for selecting date and time (not just date) in shiny

前端 未结 3 957
执念已碎
执念已碎 2021-02-14 02:23

In the past I have used a combination of dateInput and a slider to get date and hour for my shiny app. I was wondering if there is a better option available now as I need to col

3条回答
  •  醉梦人生
    2021-02-14 02:53

    I ran into the same problem, and I ended up making it a text field. I pre-populated the text field to show the users the proper format, and added checking (using try to make sure the field was properly formatted before doing anything.

    From UI.R

    textInput("fromDatetime", "From:", value = "9999-99-99 99:99:99" )
    

    And then in server.R

      fromDTtry = try(as.POSIXct(fromDatetime))
    
      if (!(is.POSIXct(fromDTtry))) {
        return ("From date/time not formatted correctly")
      } else {
    ... }
    

    I hope this helps. Hopefully Shiny will get around to native date/time support soon.

提交回复
热议问题