Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions R/app_server.R
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,7 @@ app_server <- function(input, output, session) {
) %>%
hot_col(
col = "Dose",
type = "numeric",
halign = "htRight"
) %>%
hot_col(
Expand All @@ -1029,7 +1030,8 @@ app_server <- function(input, output, session) {
) %>%
hot_context_menu(allowRowEdit = TRUE, allowColEdit = FALSE) %>%
hot_rows(rowHeights = 10) %>%
hot_cols(colWidths = c(50,55,55,90))
hot_cols(colWidths = c(50,55,55,90)) %>%
addHotHooks(filterKeys = TRUE, sanitize = TRUE)

editPriorDosesTableHOT
}, name = "output$editPriorDosesTable")
Expand Down Expand Up @@ -1191,8 +1193,7 @@ app_server <- function(input, output, session) {
) %>%
hot_col(
col = "Time",
halign = "htRight",
format = "0"
halign = "htRight"
) %>%
hot_col(
col = "Event",
Expand All @@ -1201,11 +1202,12 @@ app_server <- function(input, output, session) {
strict = TRUE,
halign = "htLeft",
valign = "vtMiddle",
allowInvalid=FALSE
allowInvalid = FALSE
) %>%
hot_context_menu(allowRowEdit = TRUE, allowColEdit = FALSE) %>%
hot_rows(rowHeights = 10) %>%
hot_cols(colWidths = c(50,55,90))

output$editEventsTableHTML <- renderRHandsontable(tempTableHOT)
showModal(
modalDialog(
Expand Down Expand Up @@ -1388,6 +1390,7 @@ app_server <- function(input, output, session) {
) %>%
hot_col(
col = "Target",
type = "numeric",
halign = "htRight"
) %>%
hot_context_menu(
Expand All @@ -1399,7 +1402,9 @@ app_server <- function(input, output, session) {
) %>%
hot_cols(
colWidths = c(70,70)
)
) %>%
addHotHooks(filterKeys = TRUE, sanitize = TRUE)

output$targetTableHTML <- renderRHandsontable(targetHOT)
showModal(
modalDialog(
Expand Down
18 changes: 2 additions & 16 deletions R/createHOT.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ createHOT <- function(doseTable,drugDefaults)
rhandsontable::hot_col(
col = "Dose",
type = "numeric",
halign = "htRight",
validator = "function(value, callback) {callback(true)}"
halign = "htRight"
) %>%
rhandsontable::hot_col(
col = "Units",
Expand All @@ -52,20 +51,7 @@ createHOT <- function(doseTable,drugDefaults)
HOT$x$cell <- c(HOT$x$cell, list(cell))
}

HOT <- htmlwidgets::onRender(HOT,
"
function(el, x) {
HOT <- addHotHooks(HOT, filterKeys = TRUE, sanitize = TRUE, afterChange = "hookDoseTableUpdate")

var hot = this.hot;
// do this to avoid adding duplicate callbacks on re-render
hot.removeHook('beforeKeyDown', beforeKeyDownHot);
hot.removeHook('beforeChange', beforeChangeHot);
hot.removeHook('afterChange', changeHot);
hot.addHook('beforeKeyDown', beforeKeyDownHot);
hot.addHook('beforeChange', beforeChangeHot);
hot.addHook('afterChange', changeHot);
}
"
)
return(HOT)
}
21 changes: 21 additions & 0 deletions R/shiny-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,24 @@ attachClass <- function(tag, class) {
inlineUI <- function(tag) {
attachClass(tag, "inline_ui")
}

addHotHooks <- function(hot, filterKeys = TRUE, sanitize = TRUE, ...) {
hooks <- list(...)

if (filterKeys) hooks$beforeKeyDown <- c("hookFilterKeys", hooks$beforeKeyDown)
if (sanitize) hooks$beforeChange <- c("hookSanitize", hooks$beforeChange)

js <- c("function(el, x) {", " var hot = this.hot;")

for (hookType in names(hooks)) {
for (fxn in hooks[[hookType]]) {
js <- c(js,
sprintf(" hot.removeHook('%s', %s);", hookType, fxn),
sprintf(" hot.addHook('%s', %s);", hookType, fxn)
)
}
}

js <- c(js, "}")
htmlwidgets::onRender(hot, paste(js, collapse = "\n"))
}
Loading
Loading