Skip to content

Using dates in RCAP

Nathan Eastwood edited this page Aug 24, 2016 · 2 revisions

Selecting Dates in RCAP

There are three ways of choosing dates in RCAP. We currently have two ways of selecting a date which are described below:

Date Picker

Within the form widget you will find the Date Picker form control. This allows you to assign a date to a variable. However you also need a default value created in your RCloud notebook.

variable <<- as.Date("2016/01/01")

We can then use the value from the Date Picker as we would in R. For example, we could create a sequence of dates

createDateSequence <<- function() {
  seq(from = variable, to = as.Date("2017/01/01"), by = "days") 
}

Date Range Picker

The second way of selecting dates is by using the Date Range Picker form control. This control has two options.

Using an Interval

Under "Use interval" of the Date Range form control, if you select one of "Days", "Weeks", "Months" or "Years", then in rcap.html you will be able to choose a start date and how many units you wish to increase this by. We can access each of these components in the RCloud notebook. First we set up a default containing the names from, intervalType and interval.

variable <<- list(from = as.Date("2016/01/01"), 
                  intervalType = "months", 
                  interval = 3) 

Then we set up a function to utilise and access each of these components

createDateSequence <<- function() {
  seq(from = variable$from,
      by = variable$intervalType,
      length.out = variable$interval)
}

Selecting Start and End Dates

Under "Use interval" of the Date Range form control, selecting "Select an option" (i.e. the default) will allow the user to select both start and end dates. These values are then returned by the client side to the RCloud notebook from which they can be called. First, we again need to set up a default list containing dates assigned to the names from and to.

variable <<- list(from = as.Date("2015/01/01"), to = as.Date("2016/01/01"))

We can then create a function that uses these dates

createDateSequence <<- function() {
  seq(from = variable$from, to = variable$to, by = "days")
}

Notes

  • The values returned by the client side are of class date and so we do not need to wrap them with as.Date or similar.