-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathjstree-shiny.R
32 lines (31 loc) · 1.24 KB
/
jstree-shiny.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#' @title Shiny bindings for jstree
#'
#' @description Output and render functions for using \code{jstree} within
#' Shiny applications and interactive Rmd documents. See examples with
#' \code{\link{jstreeExample}}.
#'
#' @param outputId output variable to read from
#' @param width,height must be a valid CSS unit (like \code{'100\%'},
#' \code{'400px'}, \code{'auto'}) or a number, which will be coerced to a
#' string and have \code{'px'} appended
#' @param expr an expression that generates a \code{\link{jstree}}
#' @param env the environment in which to evaluate \code{expr}
#' @param quoted logical, whether \code{expr} is a quoted expression
#' (with \code{quote()}); this is useful if you want to save an expression
#' in a variable
#'
#' @name jstree-shiny
#'
#' @importFrom htmlwidgets shinyWidgetOutput shinyRenderWidget
#' @export
jstreeOutput <- function(outputId, width = "100%", height = "auto"){
shinyWidgetOutput(
outputId, 'jstreer', width, height, package = 'jsTreeR'
)
}
#' @rdname jstree-shiny
#' @export
renderJstree <- function(expr, env = parent.frame(), quoted = FALSE) {
if(!quoted) expr <- substitute(expr) # force quoted
shinyRenderWidget(expr, jstreeOutput, env, quoted = TRUE)
}