Skip to content

Commit 313a5d5

Browse files
committed
Add %H:%M format support and update documentation
Closes #2.
1 parent b5fab07 commit 313a5d5

7 files changed

+39
-26
lines changed

DESCRIPTION

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ Title: A Time Input Widget for Shiny
44
Version: 0.1.0.9000
55
Authors@R: person("Gerhard", "Burger", email = "burger.ga@gmail.com", role = c("aut", "cre"))
66
Description: Provides a time input widget for Shiny. This widget allows intuitive time input in the
7-
'[hh]:[mm]:[ss]' (24H) format by using a separate numeric input for each part of the time. The
8-
interface with R uses 'DateTimeClasses' objects. See the project page for more information and
9-
examples.
7+
'[hh]:[mm]:[ss]' or '[hh]:[mm]' (24H) format by using a separate numeric input for each time
8+
component. The interface with R uses 'DateTimeClasses' objects. See the project page for more
9+
information and examples.
1010
License: GPL-3 | file LICENSE
1111
LazyData: TRUE
1212
Imports:

R/input-time.R

+19-12
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
#' shinyTime: A Time Input Widget for Shiny
22
#'
33
#' Provides a time input widget for Shiny. This widget allows intuitive time input in the
4-
#' \code{[hh]:[mm]:[ss]} (24H) format by using a separate numeric input for each part
5-
#' of the time. The interface with R uses \code{\link{DateTimeClasses}} objects.
4+
#' \code{[hh]:[mm]:[ss]} or \code{[hh]:[mm]} (24H) format by using a separate numeric input for each
5+
#' time component. The interface with R uses \code{\link{DateTimeClasses}} objects.
66
#'
77
#' @docType package
88
#' @name shinyTime
99
NULL
1010

1111
#' Create a time input
1212
#'
13-
#' Creates a time widget that consists of three separate numeric inputs for respectively the hours,
14-
#' minutes, and seconds. The input and output values of the time widget are instances of
13+
#' Creates a time widget that consists of separate numeric inputs for the hours, minutes, and
14+
#' seconds. The input and output values of the time widget are instances of
1515
#' \code{\link{DateTimeClasses}}, these can be converted to and from character strings with
1616
#' \code{\link{strptime}} and \code{\link{strftime}}. For a simple example app see
1717
#' \code{\link{shinyTimeExample}}.
1818
#'
1919
#' @inheritParams shiny::textInput
2020
#' @param value The desired time value. Must be a instance of \code{\link{DateTimeClasses}}.
21+
#' @param seconds Show input for seconds. Defaults to FALSE
2122
#'
2223
#' @family shinyTime functions
2324
#' @seealso \code{\link{strptime}}, \code{\link{strftime}}
@@ -34,15 +35,18 @@ NULL
3435
#' timeInput("time2", "Time:", value = Sys.time()),
3536
#'
3637
#' # Set to custom time
37-
#' timeInput("time3", "Time:", value = strptime("12:34:56", "%T"))
38+
#' timeInput("time3", "Time:", value = strptime("12:34:56", "%T")),
39+
#'
40+
#' # Use %H:%M format
41+
#' timeInput("time4", "Time:", seconds = FALSE)
3842
#' )
3943
#'
4044
#' shinyApp(ui, server = function(input, output) { })
4145
#' }
4246
#'
4347
#' @importFrom htmltools tagList singleton tags
4448
#' @export
45-
timeInput <- function(inputId, label, value = NULL) {
49+
timeInput <- function(inputId, label, value = NULL, seconds = TRUE) {
4650
if(is.null(value)) value <- getDefaultTime()
4751
value_list <- parseTimeFromValue(value)
4852
style <- "width: 5ch"
@@ -59,15 +63,18 @@ timeInput <- function(inputId, label, value = NULL) {
5963
tags$b(":"),
6064
tags$input(type="number", min="0", max="59", step="1", value = value_list$min,
6165
style = style, onchange = onchange),
62-
tags$b(":"),
63-
tags$input(type="number", min="0", max="59", step="1", value = value_list$sec,
64-
style = style, onchange = onchange)
66+
67+
if(seconds) tags$b(":") else NULL,
68+
if(seconds) tags$input(type="number", min="0", max="59", step="1", value = value_list$sec,
69+
style = style, onchange = onchange) else NULL
6570
)
6671
)
6772
)
6873
}
6974

70-
#' Change the value of a time input on the client
75+
#' Change a time input on the client
76+
#'
77+
#' Change the label and/or value of a time input
7178
#'
7279
#' @inheritParams shiny::updateTextInput
7380
#' @param value The desired time value. Must be a instance of \code{\link{DateTimeClasses}}.
@@ -99,9 +106,9 @@ updateTimeInput <- function(session, inputId, label = NULL, value = NULL) {
99106
session$sendInputMessage(inputId, message)
100107
}
101108

102-
#' Run a simple example app using the shinyTime functionality
109+
#' Show the shinyTime example app
103110
#'
104-
#' This functions runs a very simple app demonstrating the shinyTime functionality.
111+
#' Run a simple shiny app demonstrating the shinyTime functionality.
105112
#'
106113
#' @family shinyTime functions
107114
#' @importFrom shiny runApp

inst/www/input_binding_time.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ $.extend(timeInputBinding, {
3131
return {
3232
hour: values[0],
3333
min: values[1],
34-
sec: values[2]};
34+
sec: (values.length > 2) ? values[2] : 0
35+
};
3536
},
3637
setValue: function(el, value) {
3738
var $inputs = $(el).find('input');

man/shinyTime.Rd

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/shinyTimeExample.Rd

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/timeInput.Rd

+9-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/updateTimeInput.Rd

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)