-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathJBrowseR.R
84 lines (79 loc) · 2.76 KB
/
JBrowseR.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#' R interface to JBrowse 2 genome browser
#'
#' Embed a JBrowse 2 linear genome view in your Shiny app,
#' Rmd document, or interactive R console.
#'
#' @param view Which JBrowse 2 view to use. View, JsonView, ViewHg19, ViewHg38
#' @param ... The parameters passed on to the view
#' @param width The width of the htmlwidget
#' @param height The height of the htmlwidget
#' @param elementId The elementId of the htmlwidget
#'
#' @return an htmlwidget of the JBrowse 2 linear genome view.
#'
#' @import htmlwidgets
#' @export
JBrowseR <- function(view, ..., width = NULL, height = NULL, elementId = NULL) {
# describe a React component to send to the browser for rendering.
component <- reactR::component(view, list(...))
# create widget
htmlwidgets::createWidget(
name = "JBrowseR",
reactR::reactMarkup(component),
width = width,
height = height,
package = "JBrowseR",
elementId = elementId
)
}
#' Shiny bindings for JBrowseR
#'
#' Output and render functions for using JBrowseR within Shiny
#' applications and interactive Rmd documents.
#'
#' @param outputId output variable to read from
#' @param width Must be a valid CSS unit or a number, which will be coerced to a string and have \code{'px'} appended.
#' @param height Must be a valid CSS unit or a number, which will be coerced to a string and have \code{'px'} appended.
#' @param expr An expression that generates a JBrowseR
#' @param env The environment in which to evaluate \code{expr}.
#' @param quoted Is \code{expr} a quoted expression (with \code{quote()})? This
#' is useful if you want to save an expression in a variable.
#'
#' @name JBrowseR-shiny
#'
#' @return the Shiny UI bindings for a JBrowseR htmlwidget
#'
#' @export
JBrowseROutput <- function(outputId, width = "100%", height = "400px") {
htmlwidgets::shinyWidgetOutput(outputId, "JBrowseR", width, height, package = "JBrowseR")
}
#' @rdname JBrowseR-shiny
#'
#' @return the Shiny server bindings for a JBrowseR htmlwidget
#'
#' @export
renderJBrowseR <- function(expr, env = parent.frame(), quoted = FALSE) {
if (!quoted) {
expr <- substitute(expr)
} # force quoted
htmlwidgets::shinyRenderWidget(expr, JBrowseROutput, env, quoted = TRUE)
}
#' Called by HTMLWidgets to produce the widget's root element.
#'
#' @param id htmltools id
#' @param style htmltools style
#' @param class htmltools class
#' @param ... Additional arguments passed on
#'
#' @return the root HTML element to render the React component in
#'
#' @rdname JBrowseR-shiny
JBrowseR_html <- function(id, style, class, ...) {
htmltools::tagList(
# Necessary for RStudio viewer version < 1.2
reactR::html_dependency_corejs(),
reactR::html_dependency_react(),
reactR::html_dependency_reacttools(),
htmltools::tags$div(id = id, class = class, style = style)
)
}