From d7a0fa32f22c40a1c6f61d0d39798f835d266d0c Mon Sep 17 00:00:00 2001 From: pvictor Date: Wed, 7 Feb 2024 13:41:39 +0100 Subject: [PATCH] updated cal_events() example --- examples/ex-cal_events.R | 66 ++++++++++++++++++++++------------------ man/cal_events.Rd | 66 ++++++++++++++++++++++------------------ 2 files changed, 74 insertions(+), 58 deletions(-) diff --git a/examples/ex-cal_events.R b/examples/ex-cal_events.R index ca3584f9..1cb90035 100644 --- a/examples/ex-cal_events.R +++ b/examples/ex-cal_events.R @@ -2,49 +2,57 @@ library(shiny) library(toastui) calendarProps <- data.frame( - id = c("1", "2", "3"), + id = paste0("cal_", 1:3), name = c("TODO", "Meetings", "Tasks"), color = c("#FFF", "#FFF", "#000"), - bgColor = c("#E41A1C", "#377EB8", "#4DAF4A"), + backgroundColor = c("#E41A1C", "#377EB8", "#4DAF4A"), borderColor = c("#a90000", "#005288", "#0a7f1c") ) +n <- 20 +date_start <- sample( + seq(from = as.POSIXct(Sys.Date()-14), by = "1 hour", length.out = 24*7*4), + n, TRUE +) +date_end <- date_start + sample(1:25, n, TRUE) * 3600 +schedules <- data.frame( + id = paste0("event_", 1:n), + calendarId = paste0("cal_", sample(1:3, n, TRUE)), + title = LETTERS[1:n], + body = paste("Body schedule", letters[1:n]), + start = format(date_start, format = "%Y-%m-%d %H:00:00"), + end = format(date_end, format = "%Y-%m-%d %H:00:00"), + category = sample(c("allday", "time", "task"), n, TRUE), + stringsAsFactors = FALSE +) + ui <- fluidPage( tags$h2("Custom click event"), - calendarOutput(outputId = "cal") + fluidRow( + column( + width = 8, + calendarOutput(outputId = "cal") + ), + column( + width = 4, + verbatimTextOutput(outputId = "res_click") + ) + ) ) server <- function(input, output, session) { - + output$cal <- renderCalendar({ - - n <- 20 - - date_start <- sample( - seq(from = as.POSIXct(Sys.Date()-14), by = "1 hour", length.out = 24*7*4), - n, TRUE - ) - date_end <- date_start + sample(1:25, n, TRUE) * 3600 - schedules <- data.frame( - id = 1:n, - calendarId = as.character(sample(1:3, n, TRUE)), - title = LETTERS[1:n], - body = paste("Body schedule", letters[1:n]), - start = format(date_start, format = "%Y-%m-%dT%H:%00:%00"), - end = format(date_end, format = "%Y-%m-%dT%H:%00:%00"), - category = sample(c("allday", "time", "task"), n, TRUE), - stringsAsFactors = FALSE - ) - - calendar(taskView = TRUE, scheduleView = c("time", "allday")) %>% - cal_props(df = calendarProps) %>% - cal_schedules(df = schedules) %>% + calendar(useDetailPopup = FALSE) %>% + cal_props(calendarProps) %>% + cal_schedules(schedules) %>% cal_events( - clickSchedule = JS("function(event) {alert(event.schedule.id);}") + clickSchedule = JS("function(event) {Shiny.setInputValue('click', event)}") ) }) - - + + output$res_click <- renderPrint(input$click) + } if (interactive()) diff --git a/man/cal_events.Rd b/man/cal_events.Rd index 8fd2aaeb..e67211e9 100644 --- a/man/cal_events.Rd +++ b/man/cal_events.Rd @@ -52,49 +52,57 @@ library(shiny) library(toastui) calendarProps <- data.frame( - id = c("1", "2", "3"), + id = paste0("cal_", 1:3), name = c("TODO", "Meetings", "Tasks"), color = c("#FFF", "#FFF", "#000"), - bgColor = c("#E41A1C", "#377EB8", "#4DAF4A"), + backgroundColor = c("#E41A1C", "#377EB8", "#4DAF4A"), borderColor = c("#a90000", "#005288", "#0a7f1c") ) +n <- 20 +date_start <- sample( + seq(from = as.POSIXct(Sys.Date()-14), by = "1 hour", length.out = 24*7*4), + n, TRUE +) +date_end <- date_start + sample(1:25, n, TRUE) * 3600 +schedules <- data.frame( + id = paste0("event_", 1:n), + calendarId = paste0("cal_", sample(1:3, n, TRUE)), + title = LETTERS[1:n], + body = paste("Body schedule", letters[1:n]), + start = format(date_start, format = "\%Y-\%m-\%d \%H:00:00"), + end = format(date_end, format = "\%Y-\%m-\%d \%H:00:00"), + category = sample(c("allday", "time", "task"), n, TRUE), + stringsAsFactors = FALSE +) + ui <- fluidPage( tags$h2("Custom click event"), - calendarOutput(outputId = "cal") + fluidRow( + column( + width = 8, + calendarOutput(outputId = "cal") + ), + column( + width = 4, + verbatimTextOutput(outputId = "res_click") + ) + ) ) server <- function(input, output, session) { - + output$cal <- renderCalendar({ - - n <- 20 - - date_start <- sample( - seq(from = as.POSIXct(Sys.Date()-14), by = "1 hour", length.out = 24*7*4), - n, TRUE - ) - date_end <- date_start + sample(1:25, n, TRUE) * 3600 - schedules <- data.frame( - id = 1:n, - calendarId = as.character(sample(1:3, n, TRUE)), - title = LETTERS[1:n], - body = paste("Body schedule", letters[1:n]), - start = format(date_start, format = "\%Y-\%m-\%dT\%H:\%00:\%00"), - end = format(date_end, format = "\%Y-\%m-\%dT\%H:\%00:\%00"), - category = sample(c("allday", "time", "task"), n, TRUE), - stringsAsFactors = FALSE - ) - - calendar(taskView = TRUE, scheduleView = c("time", "allday")) \%>\% - cal_props(df = calendarProps) \%>\% - cal_schedules(df = schedules) \%>\% + calendar(useDetailPopup = FALSE) \%>\% + cal_props(calendarProps) \%>\% + cal_schedules(schedules) \%>\% cal_events( - clickSchedule = JS("function(event) {alert(event.schedule.id);}") + clickSchedule = JS("function(event) {Shiny.setInputValue('click', event)}") ) }) - - + + output$res_click <- renderPrint(input$click) + } if (interactive())