| Title: | Interactive Calendar and Date Picker Widget |
|---|---|
| Description: | An R interface to the 'Vanilla Calendar Pro' 'JavaScript' library (version 3.2.0, bundled) for creating interactive and customizable calendar widgets and date pickers. The package enables integration of modern calendar components in R and 'Shiny' applications, with support for date, month, year and time selection, popup input mode, theming, and in-place updates from the 'Shiny' server. |
| Authors: | Xavier Escribà Montagut [aut, cre], Yury Uvarov [ctb, cph] (Author of the bundled 'Vanilla Calendar Pro' library) |
| Maintainer: | Xavier Escribà Montagut <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 1.0.0 |
| Built: | 2026-09-27 09:45:35 UTC |
| Source: | https://github.com/escri11/vanilla-calendar-r |
Creates a Vanilla Calendar Pro calendar or date picker for use in R, R Markdown and Shiny applications.
VanillaCalendar( options = list(), width = NULL, height = NULL, elementId = NULL )VanillaCalendar( options = list(), width = NULL, height = NULL, elementId = NULL )
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. |
width, height
|
Must be a valid CSS unit (like |
elementId |
An optional ID for the widget element. |
An object of class htmlwidget.
When rendered in Shiny, the widget reports its state back to the server.
For an output with id "cal":
input$cal_selectedA Date vector 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", when
selectionTimeMode is enabled.
input$cal_weekA list with week and year, when
enableWeekNumbers is enabled and a week number is clicked.
input$cal_readyTRUE once the calendar has initialised.
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".
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.
VanillaCalendarProxy() to update a calendar in place from Shiny.
# 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" )# 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" )
Output and render functions for using VanillaCalendar within Shiny applications and interactive Rmd documents.
VanillaCalendarOutput(outputId, width = "100%", height = "400px") renderVanillaCalendar(expr, env = parent.frame(), quoted = FALSE)VanillaCalendarOutput(outputId, width = "100%", height = "400px") renderVanillaCalendar(expr, env = parent.frame(), quoted = FALSE)
outputId |
output variable to read from |
width, height
|
Must be a valid CSS unit (like |
expr |
An expression that generates a VanillaCalendar |
env |
The environment in which to evaluate |
quoted |
Is |
VanillaCalendarOutput() returns a Shiny output element;
renderVanillaCalendar() returns a Shiny render function.
# Only run examples in interactive R sessions if (interactive()) { library(shiny) library(VanillaCalendar) ui <- fluidPage( VanillaCalendarOutput("calendar"), verbatimTextOutput("dates") ) server <- function(input, output) { output$calendar <- renderVanillaCalendar({ VanillaCalendar( options = list( type = "default", locale = "en", selectionDatesMode = "multiple" ) ) }) output$dates <- renderPrint(input$calendar_selected) } shinyApp(ui, server) }# Only run examples in interactive R sessions if (interactive()) { library(shiny) library(VanillaCalendar) ui <- fluidPage( VanillaCalendarOutput("calendar"), verbatimTextOutput("dates") ) server <- function(input, output) { output$calendar <- renderVanillaCalendar({ VanillaCalendar( options = list( type = "default", locale = "en", selectionDatesMode = "multiple" ) ) }) output$dates <- renderPrint(input$calendar_selected) } shinyApp(ui, server) }
VanillaCalendarProxy() creates a handle to a calendar that is already
rendered, so that it can be changed without re-rendering it — the calendar
keeps its position, focus and selection instead of flickering back to its
initial state. The methods map onto the
Calendar instance methods
of Vanilla Calendar Pro.
vcSet() applies new options to the calendar.
vcUpdate() re-renders the calendar with its current options.
vcShow() and vcHide() show and hide a popup calendar in
input mode.
vcDestroy() removes the calendar from the page.
VanillaCalendarProxy(id, session = shiny::getDefaultReactiveDomain()) vcSet(proxy, options, reset = NULL) vcUpdate(proxy, reset = NULL) vcShow(proxy) vcHide(proxy) vcDestroy(proxy)VanillaCalendarProxy(id, session = shiny::getDefaultReactiveDomain()) vcSet(proxy, options, reset = NULL) vcUpdate(proxy, reset = NULL) vcShow(proxy) vcHide(proxy) vcDestroy(proxy)
id |
The output id of the calendar, as used in
|
session |
The Shiny session object. |
proxy |
A |
options |
A named list of options to apply, handled exactly as in
|
reset |
Optional named list overriding which parts of the calendar are
reset to their option values, with any of the logical entries |
The proxy object, invisibly, so calls can be piped.
if (interactive()) { library(shiny) library(VanillaCalendar) ui <- fluidPage( selectInput("theme", "Theme", c("light", "dark")), actionButton("clear", "Clear selection"), VanillaCalendarOutput("cal") ) server <- function(input, output, session) { output$cal <- renderVanillaCalendar( VanillaCalendar(list(selectionDatesMode = "multiple")) ) observeEvent(input$theme, { vcSet(VanillaCalendarProxy("cal"), list(selectedTheme = input$theme)) }) observeEvent(input$clear, { vcSet(VanillaCalendarProxy("cal"), list(selectedDates = list()), reset = list(dates = TRUE)) }) } shinyApp(ui, server) }if (interactive()) { library(shiny) library(VanillaCalendar) ui <- fluidPage( selectInput("theme", "Theme", c("light", "dark")), actionButton("clear", "Clear selection"), VanillaCalendarOutput("cal") ) server <- function(input, output, session) { output$cal <- renderVanillaCalendar( VanillaCalendar(list(selectionDatesMode = "multiple")) ) observeEvent(input$theme, { vcSet(VanillaCalendarProxy("cal"), list(selectedTheme = input$theme)) }) observeEvent(input$clear, { vcSet(VanillaCalendarProxy("cal"), list(selectedDates = list()), reset = list(dates = TRUE)) }) } shinyApp(ui, server) }