Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
base repository: burgerga/shinyTime
Choose a Base Repository
base: v0.1.0
head repository: burgerga/shinyTime
Choose a Head Repository
compare: v0.2.0
  • 8 commits
  • 11 files changed
  • 0 comments
  • 1 contributor
Commits on Jul 18, 2016
Commits on Jul 19, 2016
- oninput was too agressive, use onchange
- First cast to number, before attempting to pad

Closes #1 and closes #3
Closes #2.
Commits on Jul 20, 2016
Showing with 97 additions and 53 deletions.
  1. +13 −2 CHANGELOG.md
  2. +4 −4 DESCRIPTION
  3. +22 −15 R/input-time.R
  4. +22 −11 README.Rmd
  5. +14 −8 README.md
  6. +5 −2 cran-comments.md
  7. +2 −1 inst/www/input_binding_time.js
  8. +2 −2 man/shinyTime.Rd
  9. +2 −2 man/shinyTimeExample.Rd
  10. +9 −4 man/timeInput.Rd
  11. +2 −2 man/updateTimeInput.Rd
@@ -3,8 +3,19 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
Also [Keep a CHANGELOG](http://keepachangelog.com/).

## Unreleased
## [Unreleased]

## [0.2.0] - 2016-07-20
### Added
- Support for input in the %H:%M format (without seconds)

### Fixed
- Fixed padding problem on keyboard input
- Keyboard input now properly causes change events

## 0.1.0 - 2016-07-18
### Added
- Initial release
- Initial release

[Unreleased]: https://github.com/burgerga/shinyTime/compare/v0.2.0...HEAD
[0.2.0]: https://github.com/burgerga/shinyTime/compare/v0.1.0...v0.2.0
@@ -1,12 +1,12 @@
Package: shinyTime
Type: Package
Title: A Time Input Widget for Shiny
Version: 0.1.0
Version: 0.2.0
Authors@R: person("Gerhard", "Burger", email = "burger.ga@gmail.com", role = c("aut", "cre"))
Description: Provides a time input 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. The
interface with R uses 'DateTimeClasses' objects. See the project page for more information and
examples.
'[hh]:[mm]:[ss]' or '[hh]:[mm]' (24H) format by using a separate numeric input for each time
component. The interface with R uses 'DateTimeClasses' objects. See the project page for more
information and examples.
License: GPL-3 | file LICENSE
LazyData: TRUE
Imports:
@@ -1,23 +1,24 @@
#' shinyTime: A Time Input Widget for Shiny
#'
#' Provides a time input widget for Shiny. This widget allows intuitive time input in the
#' \code{[hh]:[mm]:[ss]} (24H) format by using a separate numeric input for each part
#' of the time. The interface with R uses \code{\link{DateTimeClasses}} objects.
#' \code{[hh]:[mm]:[ss]} or \code{[hh]:[mm]} (24H) format by using a separate numeric input for each
#' time component. The interface with R uses \code{\link{DateTimeClasses}} objects.
#'
#' @docType package
#' @name shinyTime
NULL

#' Create a time input
#'
#' Creates a time widget that consists of three separate numeric inputs for respectively the hours,
#' minutes, and seconds. The input and output values of the time widget are instances of
#' Creates a time widget that consists of separate numeric inputs for the hours, minutes, and
#' seconds. The input and output values of the time widget are instances of
#' \code{\link{DateTimeClasses}}, these can be converted to and from character strings with
#' \code{\link{strptime}} and \code{\link{strftime}}. For a simple example app see
#' \code{\link{shinyTimeExample}}.
#'
#' @inheritParams shiny::textInput
#' @param value The desired time value. Must be a instance of \code{\link{DateTimeClasses}}.
#' @param seconds Show input for seconds. Defaults to FALSE
#'
#' @family shinyTime functions
#' @seealso \code{\link{strptime}}, \code{\link{strftime}}
@@ -34,19 +35,22 @@ NULL
#' 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)
#' )
#'
#' shinyApp(ui, server = function(input, output) { })
#' }
#'
#' @importFrom htmltools tagList singleton tags
#' @export
timeInput <- function(inputId, label, value = NULL) {
timeInput <- function(inputId, label, value = NULL, seconds = TRUE) {
if(is.null(value)) value <- getDefaultTime()
value_list <- parseTimeFromValue(value)
style <- "width: 5ch"
oninput <- "if(this.value < 10) this.value = '0' + this.value"
onchange <- "var value = (+this.value); this.value = value < 10 ? '0' + value: value;"
tagList(
singleton(tags$head(
tags$script(src = "shinyTime/input_binding_time.js")
@@ -55,19 +59,22 @@ timeInput <- function(inputId, label, value = NULL) {
controlLabel(inputId, label),
tags$div(class = "input-group",
tags$input(type="number", min="0", max="23", step="1", value = value_list$hour,
style = style, oninput = oninput),
style = style, onchange = onchange),
tags$b(":"),
tags$input(type="number", min="0", max="59", step="1", value = value_list$min,
style = style, oninput = oninput),
tags$b(":"),
tags$input(type="number", min="0", max="59", step="1", value = value_list$sec,
style = style, oninput = oninput)
style = style, onchange = onchange),

if(seconds) tags$b(":") else NULL,
if(seconds) tags$input(type="number", min="0", max="59", step="1", value = value_list$sec,
style = style, onchange = onchange) else NULL
)
)
)
}

#' Change the value of a time input on the client
#' Change a time input on the client
#'
#' Change the label and/or value of a time input
#'
#' @inheritParams shiny::updateTextInput
#' @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) {
session$sendInputMessage(inputId, message)
}

#' Run a simple example app using the shinyTime functionality
#' Show the shinyTime example app
#'
#' This functions runs a very simple app demonstrating the shinyTime functionality.
#' Run a simple shiny app demonstrating the shinyTime functionality.
#'
#' @family shinyTime functions
#' @importFrom shiny runApp
@@ -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)

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

@@ -32,23 +34,32 @@ ui <- fluidPage(
# Set to current time
timeInput("time2", "Time:", value = Sys.time()),
# Set to custom time using
timeInput("time3", "Time:", value = strptime("12:34:56", "%T"))
# Set to custom time
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.

To retrieve the value, take note that the value 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 example try the `shinyTimeExample()` function in the package.
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')`.
@@ -2,9 +2,9 @@ shinyTime
================

<!-- README.md is generated from README.Rmd. Please edit that file -->
[![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.
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
=====
@@ -18,17 +18,23 @@ As the `shinyTime` package mimics the existing shiny functionality, using the pa
# Set to current time
timeInput("time2", "Time:", value = Sys.time()),

# Set to custom time using
timeInput("time3", "Time:", value = strptime("12:34:56", "%T"))
# Set to custom time
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.

To retrieve the value, take note that the value 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 example try the `shinyTimeExample()` function in the package.
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')`.
@@ -10,5 +10,8 @@ There was 1 NOTE:

* checking CRAN incoming feasibility ... NOTE
Maintainer: ‘Gerhard Burger <burger.ga@gmail.com>’

This is my first package submission to CRAN

Days since last update: 1

Terribly sorry, the package turned out to have a usability bug

@@ -31,7 +31,8 @@ $.extend(timeInputBinding, {
return {
hour: values[0],
min: values[1],
sec: values[2]};
sec: (values.length > 2) ? values[2] : 0
};
},
setValue: function(el, value) {
var $inputs = $(el).find('input');

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

No commit comments for this range

You can’t perform that action at this time.