| Title: | A Time Input Widget for Shiny |
|---|---|
| Description: | Provides a time input widget for Shiny. This widget allows intuitive time input in the '[hh]:[mm]:[ss]' or '[hh]:[mm]' (24H and 12H) format by using a separate numeric input for each time component. The interface with R uses date-time objects. See the project page for more information and examples. |
| Authors: | Gerhard Burger [aut, cre] (ORCID: <https://orcid.org/0000-0003-1062-5576>), Nick Youngblut [aut] (ORCID: <https://orcid.org/0000-0002-7424-5276>) |
| Maintainer: | Gerhard Burger <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.0.3.9000 |
| Built: | 2026-05-22 07:17:36 UTC |
| Source: | https://github.com/burgerga/shinytime |
Run a simple shiny app demonstrating the shinyTime functionality.
shinyTimeExample()shinyTimeExample()
Other shinyTime functions:
timeInput(),
updateTimeInput()
Creates a time widget that consists of separate numeric inputs for the hours, minutes, and
seconds. The input and output values of the time widget are instances of
DateTimeClasses, these can be converted to and from character strings with
strptime and strftime.
Additionally, the input can be specified as a character string in the 'hh:mm:ss' format or an
hms class. For a simple example app see shinyTimeExample.
timeInput( inputId, label, value = NULL, seconds = TRUE, minute.steps = NULL, use.civilian = FALSE, width = NULL )timeInput( inputId, label, value = NULL, seconds = TRUE, minute.steps = NULL, use.civilian = FALSE, width = NULL )
inputId |
The |
label |
Display label for the control, or |
value |
The desired time value. Must be a instance of |
seconds |
Show input for seconds. Defaults to TRUE. |
minute.steps |
Round time to multiples of |
use.civilian |
Use civilian time (12-hour format) instead of 24-hour format. |
width |
The width of the input, e.g. |
Returns a POSIXlt object, which can be converted to
a POSIXct object with as.POSIXct for more efficient storage.
strptime, strftime, DateTimeClasses
Other shinyTime functions:
shinyTimeExample(),
updateTimeInput()
## Only run examples in interactive R sessions if (interactive()) { ui <- fluidPage( # Default value is 00:00:00 timeInput("time1", "Time:"), # Set to current time timeInput("time2", "Time:", value = Sys.time()), # Set to custom time timeInput("time3", "Time:", value = strptime("12:34:56", "%T")), # Set to custom time using hms timeInput("time4", "Time:", value = hms::as_hms("23:45:07")), # Set to custom time using character string timeInput("time5", "Time:", value = "21:32:43"), # Use hh:mm format timeInput("time6", "Time:", seconds = FALSE), # Use multiples of 5 minutes timeInput("time7", "Time:", minute.steps = 5), # Use civilian (non-military time) timeInput("time8", "Time:", use.civilian = TRUE) ) shinyApp(ui, server = function(input, output) { }) }## Only run examples in interactive R sessions if (interactive()) { ui <- fluidPage( # Default value is 00:00:00 timeInput("time1", "Time:"), # Set to current time timeInput("time2", "Time:", value = Sys.time()), # Set to custom time timeInput("time3", "Time:", value = strptime("12:34:56", "%T")), # Set to custom time using hms timeInput("time4", "Time:", value = hms::as_hms("23:45:07")), # Set to custom time using character string timeInput("time5", "Time:", value = "21:32:43"), # Use hh:mm format timeInput("time6", "Time:", seconds = FALSE), # Use multiples of 5 minutes timeInput("time7", "Time:", minute.steps = 5), # Use civilian (non-military time) timeInput("time8", "Time:", use.civilian = TRUE) ) shinyApp(ui, server = function(input, output) { }) }
Change the label and/or value of a time input
updateTimeInput(session, inputId, label = NULL, value = NULL)updateTimeInput(session, inputId, label = NULL, value = NULL)
session |
The |
inputId |
The id of the input object. |
label |
The label to set for the input object. |
value |
The desired time value. Must be a instance of |
Other shinyTime functions:
shinyTimeExample(),
timeInput()
## Only run examples in interactive R sessions if (interactive()) { ui <- fluidPage( timeInput("time", "Time:"), actionButton("to_current_time", "Current time") ) server <- function(input, output, session) { observeEvent(input$to_current_time, { updateTimeInput(session, "time", value = Sys.time()) }) } shinyApp(ui, server) }## Only run examples in interactive R sessions if (interactive()) { ui <- fluidPage( timeInput("time", "Time:"), actionButton("to_current_time", "Current time") ) server <- function(input, output, session) { observeEvent(input$to_current_time, { updateTimeInput(session, "time", value = Sys.time()) }) } shinyApp(ui, server) }