|
76 | 76 | #' \describe{
|
77 | 77 | #' \item{output}{a named list including a component `id` and `property`}
|
78 | 78 | #' \item{params}{an unnamed list of [input] and [state] statements, each with defined `id` and `property`}
|
79 |
| -#' \item{func}{any valid R function which generates [output] provided [input] and/or [state] arguments} |
| 79 | +#' \item{func}{any valid R or JavaScript function which generates [output] provided [input] and/or [state] arguments} |
80 | 80 | #' }
|
81 | 81 | #' The `output` argument defines which layout component property should
|
82 | 82 | #' receive the results (via the [output] object). The events that
|
83 | 83 | #' trigger the callback are then described by the [input] (and/or [state])
|
84 | 84 | #' object(s) (which should reference layout components), which become
|
85 |
| -#' argument values for the callback handler defined in `func`. |
86 |
| -#' } |
87 |
| -#' \item{`clientside_callback(output = NULL, params = NULL, clientside_function = NULL)`}{ |
88 |
| -#' A callback function defintion. The `clientside_function` argument accepts a call |
89 |
| -#' to clientsideFunction(), which describes the locally served JavaScript |
90 |
| -#' function to call, and `output` defines which layout component property |
91 |
| -#' should adopt the results (via an [output] object). To determine what |
92 |
| -#' events trigger this callback, provide [input] (and/or [state]) object(s) |
93 |
| -#' (which should reference layout components) by passing them within `params` to `clientside_function`. |
| 85 | +#' argument values for the callback handler defined in `func`.] |
| 86 | +#' |
| 87 | +#' `func` may either be an anonymous R function, or a call to |
| 88 | +#' `clientsideFunction()`, which describes a locally served JavaScript |
| 89 | +#' function instead. The latter defines a "clientside callback", which |
| 90 | +#' updates components without passing data to and from the Dash backend. |
| 91 | +#' The latter may offer improved performance relative to callbacks written |
| 92 | +#' in R. |
94 | 93 | #' }
|
95 | 94 | #' \item{`run_server(host = Sys.getenv('DASH_HOST', "127.0.0.1"),
|
96 | 95 | #' port = Sys.getenv('DASH_PORT', 8050), block = TRUE, showcase = FALSE, ...)`}{
|
@@ -544,30 +543,19 @@ Dash <- R6::R6Class(
|
544 | 543 | inputs <- params[vapply(params, function(x) 'input' %in% attr(x, "class"), FUN.VALUE=logical(1))]
|
545 | 544 | state <- params[vapply(params, function(x) 'state' %in% attr(x, "class"), FUN.VALUE=logical(1))]
|
546 | 545 |
|
| 546 | + if (is.function(func)) { |
| 547 | + clientside_function <- NULL |
| 548 | + } else { |
| 549 | + clientside_function <- func |
| 550 | + func <- NULL |
| 551 | + } |
| 552 | + |
547 | 553 | # register the callback_map
|
548 | 554 | private$callback_map <- insertIntoCallbackMap(private$callback_map,
|
549 | 555 | inputs,
|
550 | 556 | output,
|
551 | 557 | state,
|
552 | 558 | func,
|
553 |
| - clientside_function=NULL) |
554 |
| - }, |
555 |
| - |
556 |
| - # ------------------------------------------------------------------------ |
557 |
| - # clientside callback registration |
558 |
| - # ------------------------------------------------------------------------ |
559 |
| - |
560 |
| - clientside_callback = function(output, params, clientside_function) { |
561 |
| - assert_valid_callbacks(output, params, clientside_function) |
562 |
| - |
563 |
| - inputs <- params[vapply(params, function(x) 'input' %in% attr(x, "class"), FUN.VALUE=logical(1))] |
564 |
| - state <- params[vapply(params, function(x) 'state' %in% attr(x, "class"), FUN.VALUE=logical(1))] |
565 |
| - |
566 |
| - private$callback_map <- insertIntoCallbackMap(private$callback_map, |
567 |
| - inputs, |
568 |
| - output, |
569 |
| - state, |
570 |
| - func = NULL, |
571 | 559 | clientside_function)
|
572 | 560 | },
|
573 | 561 |
|
|
0 commit comments