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

前端 未结 3 958
执念已碎
执念已碎 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:51

    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!

提交回复
热议问题