1
1
# ' shinyTime: A Time Input Widget for Shiny
2
2
# '
3
3
# ' 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.
6
6
# '
7
7
# ' @docType package
8
8
# ' @name shinyTime
9
9
NULL
10
10
11
11
# ' Create a time input
12
12
# '
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
15
15
# ' \code{\link{DateTimeClasses}}, these can be converted to and from character strings with
16
16
# ' \code{\link{strptime}} and \code{\link{strftime}}. For a simple example app see
17
17
# ' \code{\link{shinyTimeExample}}.
18
18
# '
19
19
# ' @inheritParams shiny::textInput
20
20
# ' @param value The desired time value. Must be a instance of \code{\link{DateTimeClasses}}.
21
+ # ' @param seconds Show input for seconds. Defaults to FALSE
21
22
# '
22
23
# ' @family shinyTime functions
23
24
# ' @seealso \code{\link{strptime}}, \code{\link{strftime}}
34
35
# ' timeInput("time2", "Time:", value = Sys.time()),
35
36
# '
36
37
# ' # 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)
38
42
# ' )
39
43
# '
40
44
# ' shinyApp(ui, server = function(input, output) { })
41
45
# ' }
42
46
# '
43
47
# ' @importFrom htmltools tagList singleton tags
44
48
# ' @export
45
- timeInput <- function (inputId , label , value = NULL ) {
49
+ timeInput <- function (inputId , label , value = NULL , seconds = TRUE ) {
46
50
if (is.null(value )) value <- getDefaultTime()
47
51
value_list <- parseTimeFromValue(value )
48
52
style <- " width: 5ch"
@@ -59,15 +63,18 @@ timeInput <- function(inputId, label, value = NULL) {
59
63
tags $ b(" :" ),
60
64
tags $ input(type = " number" , min = " 0" , max = " 59" , step = " 1" , value = value_list $ min ,
61
65
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
65
70
)
66
71
)
67
72
)
68
73
}
69
74
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
71
78
# '
72
79
# ' @inheritParams shiny::updateTextInput
73
80
# ' @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) {
99
106
session $ sendInputMessage(inputId , message )
100
107
}
101
108
102
- # ' Run a simple example app using the shinyTime functionality
109
+ # ' Show the shinyTime example app
103
110
# '
104
- # ' This functions runs a very simple app demonstrating the shinyTime functionality.
111
+ # ' Run a simple shiny app demonstrating the shinyTime functionality.
105
112
# '
106
113
# ' @family shinyTime functions
107
114
# ' @importFrom shiny runApp
0 commit comments