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

前端 未结 3 1029
眼角桃花
眼角桃花 2021-02-14 02:16

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 03:12

    You can now use the package shinyTime to intuitively input time into a Shiny App. At the moment it works with separate numeric inputs, that together make up time in the %H:%M or %H:%M:%S format. Getting and setting the value in R is done with a DateTime object.

    Example usage (also see the example on shinyapps):

    library(shiny)
    library(shinyTime)
    
    ui <- fluidPage(
    
       titlePanel("shinyTime Example App"),
    
       sidebarLayout(
          sidebarPanel(
            timeInput("time_input", "Enter time", value = strptime("12:34:56", "%T"))
          ),
    
          mainPanel(
            textOutput("time_output")
          )
       )
    )
    
    server <- function(input, output, session) {
      output$time_output <- renderText(strftime(input$time_input, "%T"))
    }
    
    shinyApp(ui, server)
    

    Disclaimer: I am the package author. Feedback and suggestions most welcome!

提交回复
热议问题