-
Notifications
You must be signed in to change notification settings - Fork 13
Using 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:
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")
}
The second way of selecting dates is by using the Date Range Picker form control. This control has two options.
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)
}
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")
}
- The values returned by the client side are of class
date
and so we do not need to wrap them withas.Date
or similar.
RCAP - RCloud powered dashboards and websites