This package puts Vanilla Calendar Pro — a small, dependency-free JavaScript calendar — into R. Every calendar on this page is live: click around in them.
VanillaCalendar() takes a list of options and returns a
widget.
The options are the ones in the Vanilla Calendar Pro reference, written exactly as they are documented there. Nothing is renamed, so when you read the upstream docs you can use what you find directly.
selectionDatesMode decides how many dates the user can
pick.
| Value | Behaviour |
|---|---|
"single" |
One date at a time (the default) |
"multiple" |
Any number of separate dates |
"multiple-ranged" |
A start and an end, with everything between highlighted |
FALSE |
Nothing selectable, a read-only calendar |
VanillaCalendar(
options = list(selectionDatesMode = "multiple-ranged", locale = "en"),
height = "380px"
)Pre-select dates with selectedDates. R Date
objects are converted for you, and a single date does not need wrapping
in a list.
VanillaCalendar(
options = list(
locale = "en",
dateMin = Sys.Date(), # nothing in the past
dateMax = Sys.Date() + 30, # nothing beyond a month out
disableWeekdays = c(0, 6), # no weekends; Sunday is 0
disableDates = Sys.Date() + 3, # and not that one either
displayDisabledDates = TRUE
),
height = "380px"
)disableDatesPast = TRUE is a shortcut for “nothing
before today”, and enableDates works the other way round,
allowing only what you list.
VanillaCalendar(
options = list(
locale = "en",
type = "multiple",
displayMonthsCount = 2,
displayDatesOutside = FALSE,
selectionDatesMode = "multiple-ranged"
),
width = "100%",
height = "400px"
)type also takes "month" and
"year" for calendars that only pick a month or a year.
locale takes any BCP 47 tag the browser knows, so the
month and weekday names come from the browser rather than from a
translation table shipped here.
For full control, pass month and weekday names yourself:
"system" follows the page instead, reading the attribute
named by themeAttrDetect ("html[data-theme]"
by default). In a bslib app, set
themeAttrDetect = "html[data-bs-theme]".
Option names are checked against the bundled library, so a typo tells you rather than quietly doing nothing:
cal <- VanillaCalendar(options = list(selectionDateMode = "single"))
#> Warning: Unknown Vanilla Calendar option(s) ignored by the calendar:
#> selectionDateModeAnd selectedMonth is a library option, so it counts
months from 0 like JavaScript does — selectedMonth = 11 is
December. The Shiny input input$cal_selected_month
is converted to the R convention of 1-12.
vignette("shiny") for reading selections into R and
updating calendars from the server.