-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathresetButton.R
51 lines (38 loc) · 2.11 KB
/
resetButton.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
# working example for resetting selected rows in DT Shiny
library(shiny)
library(shinyWidgets)
data("iris")
ui <- basicPage(
h2("Select Rows"),
DT::dataTableOutput('mytable'),
actionButton("clear1", label = "Reset"))
server <- function(input, output,session) {
mydata <- reactive({ iris })
output$mytable = DT::renderDataTable(datatable(mydata(),
rownames = FALSE, escape = FALSE,
selection = list(mode = 'multiple',target = 'row'),
filter = 'top',
extensions = c('Buttons'),
options = list(
dom = 'Bfrtip',
autoWidth = TRUE,
buttons = list('pageLength'),
searchHighlight = TRUE,
initComplete = JS("function(settings, json) {",
"$(this.api().table().header()).css({'background-color': '#4C4C4C', 'color': '#fff'});",
"}"),
scrollX = TRUE,
scrollY = TRUE,
escape = FALSE
),
class = 'nowrap display'))
# for resetting selection
proxy = dataTableProxy('mytable')
observeEvent(input$selectButton, {
proxy %>% selectRows(as.numeric(selectedRow()))
})
observeEvent(input$clear1, {
proxy %>% selectRows(NULL)
})
}
runApp(list(ui = ui, server = server))