-
Notifications
You must be signed in to change notification settings - Fork 157
/
Copy pathvirtual-select-funcs.R
90 lines (77 loc) · 1.95 KB
/
virtual-select-funcs.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
# labelRenderer example ----
library(shiny)
library(shinyWidgets)
ui <- fluidPage(
tags$head(
tags$script(HTML("
function colorText(data) {
let text = `<span style='color: ${data.label};'>${data.label}</span>`;
return text;
}"
)),
),
tags$h1("Custom LabelRenderer"),
br(),
fluidRow(
column(
width = 6,
virtualSelectInput(
inputId = "search",
label = "Color picker",
choices = c("red", "blue", "green", "#cbf752"),
width = "100%",
keepAlwaysOpen = TRUE,
labelRenderer = "colorText",
allowNewOption = TRUE
)
)
)
)
server <- function(input, output, session) {}
if (interactive())
shinyApp(ui, server)
# onServerSearch example ----
library(shiny)
library(shinyWidgets)
ui <- fluidPage(
tags$head(
tags$script(HTML(r"(
// Main function that is called
function searchLabel(searchValue, virtualSelect) {
// Words to search for - split by a space
const searchWords = searchValue.split(/[\s]/);
// Update visibility
const found = virtualSelect.options.map(opt => {
opt.isVisible = searchWords.every(word => opt.label.includes(word));
return opt;
});
virtualSelect.setServerOptions(found);
}
)"
)),
),
tags$h1("Custom onServerSearch"),
br(),
fluidRow(
column(
width = 6,
virtualSelectInput(
inputId = "search",
label = "Better search",
choices = c("This is some random long text",
"This text is long and looks differently",
"Writing this text is a pure love",
"I love writing!"
),
width = "100%",
keepAlwaysOpen = TRUE,
search = TRUE,
autoSelectFirstOption = FALSE,
onServerSearch = "searchLabel"
)
)
)
)
server <- function(input, output, session) {}
if (interactive())
shinyApp(ui, server)