Skip to content

Commit

Permalink
updated cal_events() example
Browse files Browse the repository at this point in the history
  • Loading branch information
pvictor committed Feb 7, 2024
1 parent ce01728 commit d7a0fa3
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 58 deletions.
66 changes: 37 additions & 29 deletions examples/ex-cal_events.R
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
66 changes: 37 additions & 29 deletions man/cal_events.Rd

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

0 comments on commit d7a0fa3

Please sign in to comment.