-
Notifications
You must be signed in to change notification settings - Fork 55
/
shiny-mapping.R
84 lines (73 loc) · 2.58 KB
/
shiny-mapping.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
#' Try to deduce the shiny input/output element type from its name
#'
#' @param name The name of the Shiny input or output to search for.
#' @param iotype It is possible that an input has the same name as
#' an output, and in this case there is no way to get element without
#' knowing whether it is an input or output element.
#'
#' @noRd
sd_findWidget <- function(self, private, name, iotype) {
"!DEBUG finding a widget `name` (`iotype`)"
css <- if (iotype == "auto") {
paste0("#", name)
} else if (iotype == "input") {
paste0("#", name, ".shiny-bound-input")
} else if (iotype == "output") {
paste0("#", name, ".shiny-bound-output")
}
els <- self$findElements(css = css)
if (length(els) == 0) {
abort(paste0(
"Cannot find ",
if (iotype != "auto") paste0(iotype, " "),
"widget ", name
))
} else if (length(els) > 1) {
warning(
"Multiple ",
if (iotype != "auto") paste0(iotype, " "),
"widgets with id ", name
)
}
type <- els[[1]]$executeScript(
"var el = $(arguments[0]);
if (el.data('shinyInputBinding') !== undefined) {
return ['input', el.data('shinyInputBinding').name];
} else {
var name = el.data('shinyOutputBinding').binding.name;
if (name == 'shiny.textOutput' && el[0].tagName == 'PRE') {
return ['output', 'shiny.verbatimTextOutput'];
} else {
return ['output', name];
}
}"
)
## We could use the JS names as well, but it is maybe better to use
## the names the users encounter with in the Shiny R docs
widget_names <- c(
"shiny.actionButtonInput" = "actionButton",
"shiny.checkboxInput" = "checkboxInput",
"shiny.checkboxGroupInput" = "checkboxGroupInput",
"shiny.dateInput" = "dateInput",
"shiny.dateRangeInput" = "dateRangeInput",
"shiny.fileInputBinding" = "fileInput",
"shiny.numberInput" = "numericInput",
"shiny.radioInput" = "radioButtons",
"shiny.selectInput" = "selectInput",
"shiny.sliderInput" = "sliderInput",
"shiny.textInput" = "textInput",
"shiny.passwordInput" = "passwordInput",
"shiny.bootstrapTabInput" = "tabsetPanel",
"shiny.textOutput" = "textOutput",
"shiny.verbatimTextOutput" = "verbatimTextOutput",
"shiny.htmlOutput" = "htmlOutput",
"shiny.imageOutput" = "plotOutput",
"datatables" = "tableOutput"
)
Widget$new(
name = name,
element = els[[1]],
type = unname(widget_names[type[[2]]] %|NA|% type[[2]]),
iotype = type[[1]]
)
}