forked from Displayr/rhtmlTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhtmlwidget.R
71 lines (63 loc) · 1.5 KB
/
htmlwidget.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
# TEMPLATE! - update the method descriptions.
#' rhtmlTemplate HTML Widget
#'
#' @description A HTMLWidget that ...
#'
#' @section Usage Scenarios:
#'
#' Scenario 1: Blah blah
#'
#' @param param1 is a good param
#'
#' @examples
#'
#' rhtmlTemplate::template('{}')
#'
#' @author First Last <first.last@gmail.com>
#'
#' @source https://github.com/Displayr/rhtmlTemplate
#'
#' @import htmlwidgets
#'
#' @export
#'
# TEMPLATE! - update the function name
template <- function(settingsJsonString = '{}') {
DEFAULT_WIDGET_WIDTH <- 600
DEFAULT_WIDGET_HEIGHT <- 600
parsedInput <- NULL
parsedInput = tryCatch({
jsonlite::fromJSON(settingsJsonString)
}, warning = function(w) {
print("warning while parsing JSON:")
print(w)
}, error = function(e) {
print("error while parsing JSON:")
print(e)
stop(e)
}, finally = {})
width <- DEFAULT_WIDGET_WIDTH
height <- DEFAULT_WIDGET_HEIGHT
if('width' %in% names(parsedInput)) {
width <- as.numeric(unlist(parsedInput['width']))
}
if('height' %in% names(parsedInput)) {
height <- as.numeric(unlist(parsedInput['height']))
}
htmlwidgets::createWidget(
# TEMPLATE! - update the name here
name = 'rhtmlTemplate',
settingsJsonString,
width = width,
height = height,
sizingPolicy = htmlwidgets::sizingPolicy(
defaultWidth = width,
defaultHeight = height,
browser.fill = TRUE,
viewer.fill = TRUE,
padding = 0
),
# TEMPLATE! - update the name here
package = 'rhtmlTemplate'
)
}