days <- input$substance_days_routine
substance <- input$substance_routine
frequency <- input$frequency_routine
add_calendar <- TRUE
if(is.null(days)) {
show_toast(title = "No Day Selected", text = "", type = "error",
position = "center", width = "50%")
add_calendar <- FALSE
}
if(substance == "") {
show_toast(title = "Missing substance", text = "", type = "error",
position = "center", width = "50%")
add_calendar <- FALSE
}
if(frequency == "") {
show_toast(title = "Missing frequency", text = "", type = "error",
position = "center", width = "50%")
add_calendar <- FALSE
}
if(add_calendar) {
id <- randomID()
table_substance_routine_data(
table_substance_routine_data() |>
add_row(
tibble(
Id = id,
`Days` = paste(days, collapse = ", "),
`Substance` = substance,
`Frequency` = frequency
)
)
)
days_date <- c(
seq(
dates_study()$P1[1],
dates_study()$P1[2],
by = 1
),
seq(
dates_study()$P2[1],
dates_study()$P2[2],
by = 1
),
seq(
dates_study()$P3[1],
dates_study()$P3[2],
by = 1
),
seq(
dates_study()$P4[1],
dates_study()$P4[2],
by = 1
)
)
days_date <- days_date[weekdays(days_date) %in% days] |>
as.character()
for (day in days_date) {
timevis_data_cal(
timevis_data_cal() |>
add_row(
tibble(
id = id,
calendarId = substances$calendar_id[substances$name_short_html == substance],
period = "Routine",
what = "Substance",
event = NA,
substance = substance,
frequency = frequency,
title = glue("{frequency} {substance}"),
body = "Routinely taken substance",
recurrenceRule = NA,
start = as.Date(day),
end = as.Date(day),
category = "allday",
location = NA,
bgColor = NA,
color = NA,
borderColor = NA
)
)
)
}
# Reset substance and frequency inputs and save on AWS.
if(input$all_substances) {
updateVirtualSelect(
session = session,
"substance_routine",
"Substance:",
choices = substances |>
prepare_choices(name_short_html, name_short_html, group),
selected = ""
)
}
if(! input$all_substances) {
updateVirtualSelect(
session = session,
"substance_routine",
"Substance",
choices = substances_names_grouped(),
selected = ""
)
}
updateVirtualSelect(
session = session,
"frequency_routine",
"Frequency",
choices = 1:100,
selected = character(0)
)
save_aws(
data = timevis_data_cal(),
data_table_routine = table_substance_routine_data(),
id = tlfb_id(),
v = tlfb_v(),
last_action = "add_substance",
session = session
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.