Learn R Programming

shinyWidgets (version 0.8.7)

time-input: Time input

Description

This widget allow to select hour and minute using the default browser time input. See developer.mozilla.org for more.

Usage

timeInput(
  inputId,
  label,
  value = NULL,
  min = NULL,
  max = NULL,
  step = NULL,
  width = NULL
)

updateTimeInput( session = getDefaultReactiveDomain(), inputId, label = NULL, value = NULL, min = NULL, max = NULL, step = NULL )

Value

A time input control that can be added to a UI definition.

Arguments

inputId

The input slot that will be used to access the value.

label

Display label for the control, or NULL for no label.

value

Initial value, foramtted as "HH:MM" or "HH:MM:SS".

min, max

Minimal and maximal value, use same format as in value.

step

It takes an integer value that equates to the number of seconds you want to increment by; the default value is 60 seconds, or one minute. If you specify a value of less than 60 seconds (1 minute), the time input will show a seconds input area alongside the hours and minutes. This property has some strange effects across browsers, so is not completely reliable.

width

The width of the input, e.g. 400px, or 100%.

session

Default Shiny session.

Examples

Run this code

library(shiny)
library(shinyWidgets)

ui <- fluidPage(
  tags$h2("Time Input"),
  fluidRow(
    column(
      width = 6,
      timeInput(
        inputId = "time1",
        label = "Time:"
      ),
      verbatimTextOutput("res1"),
      timeInput(
        inputId = "time2",
        label = "Time (default value):",
        value = "09:30"
      ),
      verbatimTextOutput("res2"),
      timeInput(
        inputId = "time3",
        label = "Time (with seconds):",
        step = 1
      ),
      verbatimTextOutput("res3")
    ),
    column(
      width = 6,
      timeInput(inputId = "time4", label = "Time:"),
      verbatimTextOutput("res4"),
      numericInput("up_h", "Update hour;", value = 0),
      numericInput("up_m", "Update minute;", value = 0)
    )
  )
)

server <- function(input, output, session) {

  output$res1 <- renderPrint(input$time1)
  output$res2 <- renderPrint(input$time2)
  output$res3 <- renderPrint(input$time3)
  output$res4 <- renderPrint(input$time4)

  observe({
    updateTimeInput(
      inputId = "time4",
      value = paste(
        # Hour and minute need to be a field of minimum width 2,
        # with zero-padding on the left
        sprintf("%02d", input$up_h),
        sprintf("%02d", input$up_m),
        sep = ":"
      )
    )
  })
}

if (interactive())
  shinyApp(ui, server)

Run the code above in your browser using DataLab