1-
21# ' Shiny bindings for detourr
32# '
43# ' Output and render functions for using detourr with shiny. The output
1312# '
1413# ' @return An output or render function that enables the use of the widget
1514# ' within shiny applications
16- # '
15+ # '
1716# ' @name detour-shiny
1817# ' @export
19- displayScatter3dOutput <- function (output_id ,
20- width = " 100%" ,
21- height = " 400px" ) {
22- htmltools :: attachDependencies(
23- shiny :: tagList(
24- htmlwidgets :: shinyWidgetOutput(output_id , " show_scatter_3d" ,
25- width , height ,
26- package = " detourr"
27- )
28- ),
29- crosstalk :: crosstalkLibs()
30- )
31- }
32-
33- # ' @rdname detour-shiny
34- # ' @export
35- displayScatter2dOutput <- function (output_id ,
36- width = " 100%" ,
37- height = " 400px" ) {
18+ detourOutput <- function (output_id ,
19+ width = " 100%" ,
20+ height = " 400px" ) {
3821 htmltools :: attachDependencies(
3922 shiny :: tagList(
40- htmlwidgets :: shinyWidgetOutput(output_id , " show_scatter_2d " ,
23+ htmlwidgets :: shinyWidgetOutput(output_id , " detourr " ,
4124 width , height ,
4225 package = " detourr"
4326 )
@@ -48,40 +31,31 @@ displayScatter2dOutput <- function(output_id,
4831
4932# ' @rdname detour-shiny
5033# ' @export
51- shinyRenderDisplayScatter2d <- function (expr , env = parent.frame(), quoted = FALSE ) {
34+ shinyRenderDetour <- function (expr , env = parent.frame(), quoted = FALSE ) {
5235 if (! quoted ) {
5336 expr <- substitute(expr )
5437 }
55- htmlwidgets :: shinyRenderWidget(expr , displayScatter2dOutput , quoted = TRUE , env = env )
56- }
57-
58- # ' @rdname detour-shiny
59- # ' @export
60- shinyRenderDisplayScatter3d <- function (expr , env = parent.frame(), quoted = FALSE ) {
61- if (! quoted ) {
62- expr <- substitute(expr )
63- }
64- htmlwidgets :: shinyRenderWidget(expr , displayScatter3dOutput , quoted = TRUE , env = env )
38+ htmlwidgets :: shinyRenderWidget(expr , detourOutput , quoted = TRUE , env = env )
6539}
6640
6741# ' Send commands to a detourr instance in a Shiny app
6842# '
6943# ' Creates a proxy object that can be used to add
7044# ' or remove points to a detour instance that has
71- # ' already being rendered using \code{\link{shinyRenderDisplayScatter3d }}.
45+ # ' already being rendered using \code{\link{shinyRenderDetour }}.
7246# ' To be used in Shiny apps only.
73- # ' @param id output id of the detourr instance
47+ # ' @param id output id of the detour instance
7448# ' @param session the Shiny session object used in the app.
7549# ' Default should work for most cases
7650# '
7751# ' @rdname detour-shiny
7852# ' @export
79- display_scatter_proxy <- function (id , session = shiny :: getDefaultReactiveDomain()) { # nolint
80- structure(list (id = id , session = session ), class = " detourr_proxy " )
53+ detour_proxy <- function (id , session = shiny :: getDefaultReactiveDomain()) { # nolint
54+ structure(list (id = id , session = session ), class = " detour_proxy " )
8155}
8256
8357# ' @title Add a set of points to an existing detourr instance in Shiny
84- # ' @param proxy Proxy object created by \code{\link{display_scatter_proxy }}
58+ # ' @param proxy Proxy object created by \code{\link{detour_proxy }}
8559# ' @param points Data.frame of points
8660# ' @param .data Original dataset used in creating the detourr instance
8761# ' @param .col_means Vector of column means of the original dataset.
@@ -95,15 +69,14 @@ display_scatter_proxy <- function(id, session = shiny::getDefaultReactiveDomain(
9569# ' @rdname detour-shiny
9670# ' @export
9771add_points <- function (
98- proxy ,
99- points ,
100- .data = NULL ,
101- .col_means = NULL ,
102- .scale_factor = NULL ,
103- colour = " black" ,
104- size = 1 ,
105- alpha = 1
106- ) {
72+ proxy ,
73+ points ,
74+ .data = NULL ,
75+ .col_means = NULL ,
76+ .scale_factor = NULL ,
77+ colour = " black" ,
78+ size = 1 ,
79+ alpha = 1 ) {
10780 if (is.null(.data )) {
10881 if (is.null(.col_means ) || is.null(.scale_factor )) {
10982 cli :: cli_abort(c(
@@ -144,7 +117,7 @@ add_points <- function(
144117
145118# ' @title Function to add a bunch of lines to existing shiny instance
146119# '
147- # ' @param proxy Proxy object created by \code{\link{display_scatter_proxy }}
120+ # ' @param proxy Proxy object created by \code{\link{detour_proxy }}
148121# ' @param edge_list Data.frame with two columns with the `from` node at first.
149122# ' The indexing of points starts with the original dataset.
150123# ' If \code{\link{add_points}} has been called before hand,
@@ -153,7 +126,9 @@ add_points <- function(
153126# ' @rdname detour-shiny
154127# ' @export
155128add_edges <- function (proxy , edge_list ) {
156- edge_list <- edge_list | > as.matrix() | > unname()
129+ edge_list <- edge_list | >
130+ as.matrix() | >
131+ unname()
157132 proxy $ message $ edges <- apply(edge_list , 1 , as.list )
158133 proxy $ session $ sendCustomMessage(" add-edges" , proxy $ message )
159134 return (proxy )
@@ -164,7 +139,7 @@ add_edges <- function(proxy, edge_list) {
164139# ' The given points will have the original opacity while the other points
165140# ' will have reduced opacity
166141# '
167- # ' @param proxy proxy object created by \code{\link{display_scatter_proxy }}
142+ # ' @param proxy proxy object created by \code{\link{detour_proxy }}
168143# ' @param point_list Numeric vector. indexes to highlight in the prinary dataset
169144# ' @param alpha The transparency value of the points outside of the point_list
170145# ' @rdname detour-shiny
@@ -183,7 +158,7 @@ highlight_points <- function(proxy, point_list, alpha = 0.3) {
183158# ' The given points will have a larger size while the rest
184159# ' remains the same
185160# '
186- # ' @param proxy proxy object created by \code{\link{display_scatter_proxy }}
161+ # ' @param proxy proxy object created by \code{\link{detour_proxy }}
187162# ' @param point_list Numeric vector. indexes to enlarge in the prinary dataset
188163# ' @param size the size of the points to be enlarged
189164# ' @rdname detour-shiny
@@ -200,7 +175,7 @@ enlarge_points <- function(proxy, point_list, size = 2) {
200175
201176
202177# ' Function to clear added points
203- # ' @param proxy proxy object created by \code{\link{display_scatter_proxy }}
178+ # ' @param proxy proxy object created by \code{\link{detour_proxy }}
204179# ' @rdname detour-shiny
205180# ' @export
206181clear_points <- function (proxy ) {
@@ -209,7 +184,7 @@ clear_points <- function(proxy) {
209184}
210185
211186# ' Function to clear added edges
212- # ' @param proxy proxy object created by \code{\link{display_scatter_proxy }}
187+ # ' @param proxy proxy object created by \code{\link{detour_proxy }}
213188# ' @rdname detour-shiny
214189# ' @export
215190clear_edges <- function (proxy ) {
@@ -218,7 +193,7 @@ clear_edges <- function(proxy) {
218193}
219194
220195# ' Function to clear highlighted points
221- # ' @param proxy proxy object created by \code{\link{display_scatter_proxy }}
196+ # ' @param proxy proxy object created by \code{\link{detour_proxy }}
222197# ' @rdname detour-shiny
223198# ' @export
224199clear_highlight <- function (proxy ) {
@@ -227,7 +202,7 @@ clear_highlight <- function(proxy) {
227202}
228203
229204# ' Function to clear enlarged points
230- # ' @param proxy proxy object created by \code{\link{display_scatter_proxy }}
205+ # ' @param proxy proxy object created by \code{\link{detour_proxy }}
231206# ' @rdname detour-shiny
232207# ' @export
233208clear_enlarge <- function (proxy ) {
@@ -238,10 +213,10 @@ clear_enlarge <- function(proxy) {
238213# ' Function to force rerender of detourr
239214# '
240215# ' Useful when detourr will not update unless put on focus
241- # ' @param proxy proxy object created by \code{\link{display_scatter_proxy }}
216+ # ' @param proxy proxy object created by \code{\link{detour_proxy }}
242217# ' @rdname detour-shiny
243218# ' @export
244219force_rerender <- function (proxy ) {
245220 proxy $ session $ sendCustomMessage(" clear-enlarge" , list (id = proxy $ id ))
246221 return (proxy )
247- }
222+ }
0 commit comments