-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathvue.R
155 lines (138 loc) · 4.62 KB
/
vue.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#' 'Vue.js' 'htmlwidget'
#'
#' Use 'Vue.js' with the convenience and flexibility of 'htmlwidgets'.
#' \code{vue} is a little different from other 'htmlwidgets' though
#' since it requires specification of the HTML tags/elements separately.
#'
#' @param app \code{list} with \code{el} and \code{data} and other pieces
#' of a 'Vue.js' app
#' @param width,height any valid \code{CSS} size unit, but in reality
#' this will not currently have any impact
#' @param elementId \code{character} id of the htmlwidget container
#' element
#' @param minified \code{logical} to indicate minified (\code{minified=TRUE}) or
#' non-minified (\code{minified=FALSE}) Vue.js
#'
#' @import htmlwidgets
#'
#' @family htmlwidget
#' @export
#' @example ./inst/examples/vue_widget_examples.R
#' @return vue htmlwidget
vue <- function(
app = list(),
width = NULL, height = NULL, elementId = NULL,
minified = TRUE
) {
# forward options using x
x = app
# create widget
hw <- htmlwidgets::createWidget(
name = 'vue',
x,
width = width,
height = height,
package = 'vueR',
elementId = elementId
)
hw$dependencies <- list(
html_dependency_vue(offline=TRUE, minified=minified)
)
hw
}
#' 'Vue.js 3' 'htmlwidget'
#'
#' Use 'Vue.js 3' with the convenience and flexibility of 'htmlwidgets'.
#' \code{vue3} is a little different from other 'htmlwidgets' though
#' since it requires specification of the HTML tags/elements separately.
#'
#' @param app \code{list} with \code{el} and \code{data} and other pieces
#' of a 'Vue.js 3' app
#' @param width,height any valid \code{CSS} size unit, but in reality
#' this will not currently have any impact
#' @param elementId \code{character} id of the htmlwidget container
#' element
#' @param minified \code{logical} to indicate minified (\code{minified=TRUE}) or
#' non-minified (\code{minified=FALSE}) Vue.js
#'
#' @import htmlwidgets
#'
#' @family htmlwidget
#' @export
#' @example ./inst/examples/vue3_widget_examples.R
#' @return vue htmlwidget
vue3 <- function(
app = list(),
width = NULL, height = NULL, elementId = NULL,
minified = TRUE
) {
# forward options using x
x = app
# will try to convert data that is not a function in widget JS
# create widget
hw <- htmlwidgets::createWidget(
name = 'vue3',
x,
width = width,
height = height,
package = 'vueR',
elementId = elementId
)
hw$dependencies <- list(
html_dependency_vue3(offline=TRUE, minified=minified)
)
hw
}
#' Shiny bindings for vue
#'
#' Output and render functions for using vue within Shiny
#' applications and interactive Rmd documents.
#'
#' @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 vue
#' @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 vue-shiny
#'
#' @export
#' @example ./inst/examples/vue3_shiny_examples.R
vueOutput <- function(outputId, width = '100%', height = '400px'){
htmlwidgets::shinyWidgetOutput(outputId, 'vue', width, height, package = 'vueR')
}
#' @rdname vue-shiny
#' @export
renderVue <- function(expr, env = parent.frame(), quoted = FALSE) {
if (!quoted) { expr <- substitute(expr) } # force quoted
htmlwidgets::shinyRenderWidget(expr, vueOutput, env, quoted = TRUE)
}
#' Shiny bindings for 'vue 3'
#'
#' Output and render functions for using 'vue 3' within Shiny
#' applications and interactive Rmd documents.
#'
#' @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 vue
#' @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 vue-shiny
#'
#' @export
vue3Output <- function(outputId, width = '100%', height = '400px'){
htmlwidgets::shinyWidgetOutput(outputId, 'vue3', width, height, package = 'vueR')
}
#' @rdname vue-shiny
#' @export
renderVue3 <- function(expr, env = parent.frame(), quoted = FALSE) {
if (!quoted) { expr <- substitute(expr) } # force quoted
htmlwidgets::shinyRenderWidget(expr, vueOutput, env, quoted = TRUE)
}