inst/hbcdtlfb/www/R/observe/add_event_P2.R

event <- input$event_P2
add_calendar <- TRUE

if(is.null(input$substance_date_P2)) {
  show_toast(title = "Missing dates", text = "", type = "error", 
             position = "center", width = "50%")
  add_calendar <- FALSE
}

if(event == "") {
  show_toast(title = "Missing event name", text = "", type = "error", 
             position = "center", width = "50%")
  add_calendar <- FALSE
}

if(add_calendar) {
  
  for (day in as.character(input$substance_date_P2)) {
    timevis_data_cal(
      timevis_data_cal() |> 
        add_row(
          tibble(
            id = randomID(),
            calendarId = 3,
            period = "Post-LMP",
            what = "Event",
            event = event,
            substance = NA,
            frequency = NA,
            title = event,
            body = "",
            recurrenceRule = NA,
            start = as.Date(day),
            end = as.Date(day), 
            category = "allday",
            location = NA,
            bgColor = NA,
            color = NA,
            borderColor = NA
          )
        )
    )
  }

}
ucsd-dsm/hbcd-tlfb documentation built on July 10, 2022, 5:46 p.m.