Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
burgerga committed Jul 19, 2016
1 parent 313a5d5 commit 7148d36
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
33 changes: 22 additions & 11 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ knitr::opts_chunk$set(
)
```

![](http://www.r-pkg.org/badges/version/shinyTime) ![](http://cranlogs.r-pkg.org/badges/grand-total/shinyTime) [![Build Status](https://travis-ci.org/burgerga/shinyTime.svg?branch=master)](https://travis-ci.org/burgerga/shinyTime)
![](http://www.r-pkg.org/badges/version/shinyTime)
![](http://cranlogs.r-pkg.org/badges/grand-total/shinyTime)
[![Build Status](https://travis-ci.org/burgerga/shinyTime.svg?branch=master)](https://travis-ci.org/burgerga/shinyTime)

This package provides a `timeInput` widget for Shiny. This widget allows intuitive time input in the
`[hh]:[mm]:[ss]` (24H) format by using a separate numeric input for each part of the time.
Setting and getting of the time in R is done with 'DateTimeClasses' objects.
`[hh]:[mm]:[ss]` or `[hh]:[mm]` (24H) format by using a separate numeric input for each time
component. Setting and getting of the time in R is done with 'DateTimeClasses' objects.

#Usage

Expand All @@ -33,22 +35,31 @@ ui <- fluidPage(
timeInput("time2", "Time:", value = Sys.time()),
# Set to custom time
timeInput("time3", "Time:", value = strptime("12:34:56", "%T"))
timeInput("time3", "Time:", value = strptime("12:34:56", "%T")),
# Use %H:%M format
timeInput("time4", "Time:", seconds = FALSE)
)
```

Note that setting an inital value is done with a [`DateTime`](http://www.inside-r.org/r-doc/base/DateTimeClasses) class,
in the same way as setting a date in `dateInput` can be done with a `Date` class.
Note that setting an inital value is done with a
[`DateTime`](http://www.inside-r.org/r-doc/base/DateTimeClasses) object, in the same way as setting
a date in `dateInput` can be done with a `Date` object.

The value retrieved will alse be in `DateTime` class. You need
to convert it to character to be able to print the time, as the default character representation
does not include the time. An example:
The value retrieved will also be a `DateTime` object. You need to convert it to character to be able
to print the time, as the default character representation does not include it. An example:

```
server <- function(input, output) {
# Print the time in [hh]:[mm]:[ss] everytime it changes
observe(print(strftime(input$time1, "%T"))),
observe(print(strftime(input$time1, "%T")))
# Print the time in [hh]:[mm] everytime it changes
observe(print(strftime(input$time4, "%R")))
}
```

For a fully functional app go to the [ShinyApps example](https://burgerga.shinyapps.io/shinyTimeExample/) (can be a bit slow) or try the `shinyTime::shinyTimeExample()` function after installing the package with `install.packages('shinyTime')`.
For a fully functional app go to the
[ShinyApps example](https://burgerga.shinyapps.io/shinyTimeExample/) (can be a bit slow) or try the
`shinyTime::shinyTimeExample()` function after installing the package with
`install.packages('shinyTime')`.
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ shinyTime
<!-- README.md is generated from README.Rmd. Please edit that file -->
![](http://www.r-pkg.org/badges/version/shinyTime) ![](http://cranlogs.r-pkg.org/badges/grand-total/shinyTime) [![Build Status](https://travis-ci.org/burgerga/shinyTime.svg?branch=master)](https://travis-ci.org/burgerga/shinyTime)

This package provides a `timeInput` widget for Shiny. This widget allows intuitive time input in the `[hh]:[mm]:[ss]` (24H) format by using a separate numeric input for each part of the time. Setting and getting of the time in R is done with 'DateTimeClasses' objects.
This package provides a `timeInput` widget for Shiny. This widget allows intuitive time input in the `[hh]:[mm]:[ss]` or `[hh]:[mm]` (24H) format by using a separate numeric input for each time component. Setting and getting of the time in R is done with 'DateTimeClasses' objects.

Usage
=====
Expand All @@ -19,16 +19,22 @@ As the `shinyTime` package mimics the existing shiny functionality, using the pa
timeInput("time2", "Time:", value = Sys.time()),

# Set to custom time
timeInput("time3", "Time:", value = strptime("12:34:56", "%T"))
timeInput("time3", "Time:", value = strptime("12:34:56", "%T")),
# Use %H:%M format
timeInput("time4", "Time:", seconds = FALSE)
)

Note that setting an inital value is done with a [`DateTime`](http://www.inside-r.org/r-doc/base/DateTimeClasses) class, in the same way as setting a date in `dateInput` can done with a `Date` class.
Note that setting an inital value is done with a [`DateTime`](http://www.inside-r.org/r-doc/base/DateTimeClasses) object, in the same way as setting a date in `dateInput` can be done with a `Date` object.

The value retrieved will alse be in `DateTime` class. You need to convert it to character to be able to print the time, as the default character representation does not include the time. An example:
The value retrieved will also be a `DateTime` object. You need to convert it to character to be able to print the time, as the default character representation does not include it. An example:

server <- function(input, output) {
# Print the time in [hh]:[mm]:[ss] everytime it changes
observe(print(strftime(input$time1, "%T"))),
observe(print(strftime(input$time1, "%T")))
# Print the time in [hh]:[mm] everytime it changes
observe(print(strftime(input$time4, "%R")))
}

For a fully functional app go to the [ShinyApps example](https://burgerga.shinyapps.io/shinyTimeExample/) (can be a bit slow) or try the `shinyTime::shinyTimeExample()` function after installing the package with `install.packages('shinyTime')`.

0 comments on commit 7148d36

Please sign in to comment.