Skip to content

Commit

Permalink
calendarPro: update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
pvictor committed Feb 7, 2025
1 parent 6fa9fd6 commit 0f4bd9a
Show file tree
Hide file tree
Showing 3 changed files with 172 additions and 17 deletions.
19 changes: 14 additions & 5 deletions R/calendar-pro-input.R
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,22 @@ updateCalendarPro <- function(inputId,
session = shiny::getDefaultReactiveDomain()) {
if (!is.null(label))
label <- doRenderTags(label)
options <- list(
selectedDates = list1(format(value, format = "%Y-%m-%d")),
selectionDatesMode = mode,
...
)
if (inherits(value, "POSIXt") & is.null(options$selectedTime))
options$selectedTime <- format(value, format = "%H:%M")
if (!is.null(options$disableWeekdays))
options$disableWeekdays <- list1(options$disableWeekdays)
if (!is.null(options$enableDates))
options$enableDates <- list1(options$enableDates)
if (!is.null(options$disableDates))
options$disableDates <- list1(options$disableDates)
message <- dropNulls(list(
label = label,
options = dropNulls(list(
selectedDates = list1(format(value, format = "%Y-%m-%d")),
selectionDatesMode = mode,
...
))
options = dropNulls(options)
))
session$sendInputMessage(inputId, message)
}
Expand Down
85 changes: 79 additions & 6 deletions examples/calendar-pro-update.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ui <- fluidPage(
tags$h2("Calendar Pro Input: update from server"),
fluidRow(
column(
width = 6,
width = 4,
calendarProInput(
inputId = "calendar",
label = "Select a date:",
Expand Down Expand Up @@ -35,7 +35,48 @@ ui <- fluidPage(
)
),
column(
width = 6
width = 4,
calendarProInput(
inputId = "time",
label = "Select date and time:",
placeholder = "Select date and time:",
selectionTimeMode = 24,
format = "%Y/%m/%d %H:%M",
width = "100%"
),
verbatimTextOutput("res2"),
actionButton(
inputId = "set_time_1",
label = "Set yesterday 11am"
),
actionButton(
inputId = "set_time_2",
label = "Set now"
)
),
column(
width = 4,
calendarProInput(
inputId = "disable",
label = "Select a date:",
placeholder = "Select a date",
width = "100%"
),
verbatimTextOutput("res3"),
radioButtons(
inputId = "disable_fridays",
label = "Disable fridays:",
choices = c("yes", "no"),
selected = "no",
inline = TRUE
),
radioButtons(
inputId = "disable_tomorrow",
label = "Disable tomorrow:",
choices = c("yes", "no"),
selected = "no",
inline = TRUE
),
)
)
)
Expand All @@ -46,20 +87,52 @@ server <- function(input, output, session) {

observeEvent(input$label, {
if (isTruthy(input$label)) {
updateCalendarPro(inputId = "calendar", label = input$label)
updateCalendarPro("calendar", label = input$label)
}
})

observeEvent(input$today, {
updateCalendarPro(inputId = "calendar", value = Sys.Date())
updateCalendarPro("calendar", value = Sys.Date())
})

observeEvent(input$today3, {
updateCalendarPro(inputId = "calendar", value = Sys.Date() + 3)
updateCalendarPro("calendar", value = Sys.Date() + 3)
})

observeEvent(input$mode, {
updateCalendarPro(inputId = "calendar", selectionDatesMode = input$mode)
updateCalendarPro("calendar", selectionDatesMode = input$mode)
}, ignoreInit = TRUE)



output$res2 <- renderPrint(input$time)

observeEvent(input$set_time_1, {
updateCalendarPro("time", value = Sys.Date() - 1, selectedTime = "11:00")
})

observeEvent(input$set_time_2, {
updateCalendarPro("time", value = Sys.time())
})



output$res3 <- renderPrint(input$disable)

observeEvent(input$disable_fridays, {
if (input$disable_fridays == "yes") {
updateCalendarPro("disable", disableWeekdays = 5)
} else {
updateCalendarPro("disable", disableWeekdays = numeric(0))
}
}, ignoreInit = TRUE)

observeEvent(input$disable_tomorrow, {
if (input$disable_tomorrow == "yes") {
updateCalendarPro("disable", disableDates = Sys.Date() + 1)
} else {
updateCalendarPro("disable", disableDates = numeric(0))
}
}, ignoreInit = TRUE)

}
Expand Down
85 changes: 79 additions & 6 deletions man/updateCalendarPro.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0f4bd9a

Please sign in to comment.