-
Notifications
You must be signed in to change notification settings - Fork 2
/
README.Rmd
84 lines (62 loc) · 2.83 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# shinyTime <a href='https://burgerga.shinyapps.io/shinyTimeExample/' target="_blank"><img src='man/figures/timeInput.png' align="right" height="138.5" /></a>
<!-- badges: start -->
[![R-CMD-check](https://github.com/burgerga/shinyTime/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/burgerga/shinyTime/actions/workflows/R-CMD-check.yaml)
[![](http://www.r-pkg.org/badges/version/shinyTime)](https://cran.r-project.org/package=shinyTime)
[![](http://cranlogs.r-pkg.org/badges/last-month/shinyTime)](https://cran.r-project.org/package=shinyTime)
<!-- badges: end -->
## Overview
shinyTime provides a `timeInput` widget for Shiny. This widget allows intuitive time input in the
`hh:mm:ss` or `hh:mm` (24-hour) format by using a separate numeric input for each time
component. Setting and getting of the time in R is done with date-time objects.
## Installation
```{r eval = FALSE}
# Install from CRAN
install.packages("shinyTime")
```
## Usage
As the `shinyTime` package mimics the existing shiny functionality, using the package is easy:
```{r eval = FALSE}
ui <- fluidPage(
# Using the default time 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)
)
```
Note that setting an initial value can be done with
[`date-time`](https://www.rdocumentation.org/packages/base/topics/DateTimeClasses) (in the same way as setting
a date in `dateInput` can be done with a `Date` object), but also with an [`hms::hms`](https://hms.tidyverse.org/reference/hms.html) object or character string in `hh:mm:ss` format.
The value retrieved will be a `date-time` object (`POSIXlt`). You need to convert it to character to be able
to show the time, as the default character representation does not include time. For example:
```{r eval=FALSE}
server <- function(input, output) {
# Print the time in hh:mm:ss everytime it changes
observe(print(strftime(input$time1, "%T")))
# Print the time in hh:mm everytime it changes
observe(print(strftime(input$time4, "%R")))
}
```
For a demo, visit the [online example app](https://burgerga.shinyapps.io/shinyTimeExample/) or try the
`shinyTime::shinyTimeExample()` function.