Creates a Vanilla Calendar Pro calendar or date picker for use in R, R Markdown and Shiny applications.
Usage
VanillaCalendar(
options = list(),
width = NULL,
height = NULL,
elementId = NULL
)Arguments
- options
A named list of Vanilla Calendar Pro options, passed to the JavaScript library. Every option documented in the upstream reference is accepted; names are validated against the bundled library version and unknown names raise a warning.
DateandPOSIXctvalues are converted to the"YYYY-MM-DD"strings the library expects, and options that must be arrays (such asselectedDates) are boxed for you, so a single date works. JavaScript callbacks can be supplied withhtmlwidgets::JS(); they run in addition to, not instead of, the Shiny inputs described below. Note that options keep the library's own conventions, soselectedMonthcounts months from 0 (11is December) even thoughinput$<id>_selected_monthis reported to R as 1-12.- width, height
Must be a valid CSS unit (like
'100\%','400px','auto') or a number, which will be coerced to a string and have'px'appended.- elementId
An optional ID for the widget element.
Shiny inputs
When rendered in Shiny, the widget reports its state back to the server.
For an output with id "cal":
input$cal_selectedA
Datevector of the selected dates (length 0 when nothing is selected).input$cal_selected_monthSelected month, 1-12.
input$cal_selected_yearSelected year.
input$cal_displayedFirst day of the displayed month, as a
Date, updated when the user clicks the arrows.input$cal_timeSelected time as a string, e.g.
"14:30", whenselectionTimeModeis enabled.input$cal_weekA list with
weekandyear, whenenableWeekNumbersis enabled and a week number is clicked.input$cal_readyTRUEonce the calendar has initialised.
Input mode
With options = list(inputMode = TRUE) the widget renders a text input and
shows the calendar as a popup, the behaviour documented under
input mode
upstream. Pair it with height = "auto".
Theming
selectedTheme accepts "light", "dark" or "system". In system mode the
library reads the theme from the attribute named by themeAttrDetect, which
defaults to "html[data-theme]". Shiny apps using bslib should set
themeAttrDetect = "html[data-bs-theme]" to follow the app theme.
See also
VanillaCalendarProxy() to update a calendar in place from Shiny.
Examples
# Basic calendar with default settings
VanillaCalendar()
# Calendar with custom options
VanillaCalendar(
options = list(
type = "default",
locale = "en",
selectionDatesMode = "multiple",
selectedDates = Sys.Date(),
selectedTheme = "light"
),
width = "500px",
height = "400px"
)
# Date picker attached to a text input
VanillaCalendar(
options = list(inputMode = TRUE, selectionDatesMode = "single"),
height = "auto"
)