substance <- input$substance_P2
frequency <- input$frequency_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(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) {
for (day in as.character(input$substance_date_P2)) {
timevis_data_cal(
timevis_data_cal() |>
add_row(
tibble(
id = randomID(),
calendarId = substances$calendar_id[substances$name_short_html == substance],
period = "Post-LMP",
what = "Substance",
event = NA,
substance = substance,
frequency = frequency,
title = glue("{frequency} {substance}"),
body = "",
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_P2",
"Substance:",
choices = substances |>
prepare_choices(name_short_html, name_short_html, group),
selected = ""
)
}
if(! input$all_substances) {
updateVirtualSelect(
session = session,
"substance_P2",
"Substance",
choices = substances_names_grouped(),
selected = ""
)
}
updateVirtualSelect(
session = session,
"frequency_P2",
"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.