-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavascript.R
More file actions
73 lines (53 loc) · 1.27 KB
/
javascript.R
File metadata and controls
73 lines (53 loc) · 1.27 KB
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
library(shiny)
library(shinyjs)
library(DT)
css <- HTML(
"table.dataTable tr.selected td.yellow {
background-color: yellow !important
}
td.yellow {
background-color: yellow !important
}"
)
js <- HTML(
"function colorizeCell(i, j,id){
var selector = 'tr:nth-child(' + i + ') td:nth-child(' + j + ')';
$(id).find(selector).addClass('yellow');
}"
)
colorizeCell <- function(i, j,id){
sprintf("colorizeCell(%d, %d, %s)", i, j, id)
}
ui <- fluidPage(
br(),
DTOutput("crop"), useShinyjs(),
tags$head(
tags$style(css),
tags$script(js)
),
br(),
DTOutput("livestock")
)
dat1 <- iris[1:5, ]
dat2 <- iris[6:15, ]
server <- function(input, output, session){
output[["crop"]] <- renderDT({
datatable(dat1, editable = TRUE)
}, server = FALSE)
output[["livestock"]] <- renderDT({
datatable(dat2, editable = TRUE)
}, server = FALSE)
observeEvent(input[["crop_cell_edit"]], {
info1 <- input[["crop_cell_edit"]]
i <- info1[["row"]]
j <- info1[["col"]]
runjs(colorizeCell(i, j+1,"crop"))
})
observeEvent(input[["livestock_cell_edit"]], {
info2 <- input[["livestock_cell_edit"]]
i <- info2[["row"]]
j <- info2[["col"]]
runjs(colorizeCell(i, j+1,"livestock"))
})
}
shinyApp(ui, server)