-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode_dt.qmd
103 lines (73 loc) · 2.46 KB
/
code_dt.qmd
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
91
92
93
94
95
96
97
98
99
100
101
102
103
---
title: "Plate Viewer"
format:
html:
page-layout: custom
theme: united
server: shiny
---
```{r}
#| context: setup
#| include: false
#| message: false
#| warning: false
library(DT)
library(gt)
library(tidyverse)
library(readxl)
library(here)
letters <- LETTERS[1:8]
dat <- read_excel(here("data/sel_GBS_2.xlsx"), sheet = "check") %>%
mutate(row_letter = LETTERS[row])
```
```{r}
#| panel: sidebar
#select values
vars_colnames <- names(dat[4:ncol(dat)])
selectInput('disp_vals', 'Displayed Values', vars_colnames, selected = vars_colnames[[9]])
plates <- setdiff(unique(dat$plate), "Plate")
selectInput('plate_no', 'Plate', choices = plates, selected = plates[1])
```
```{r}
#| panel: fill
tags$style(HTML('table.dataTable tr.selected td, table.dataTable td.selected {background-color: lightgreen !important;}'))
tags$style(HTML('table.dataTable.hover tbody tr:hover, table.dataTable.display tbody tr:hover {background-color: #cccccc !important;}'))
DT::dataTableOutput("table1", width = "500px")
```
```{r}
#| context: server
selectedData <- reactive({
dat_exp <- dat %>%
dplyr::select(plate, col, row_letter, !! sym(input$disp_vals)) %>%
filter(plate == input$plate_no) %>%
select(-plate) %>%
rename(row = row_letter) %>%
mutate(vals = !!sym(input$disp_vals))%>%
select(-!!sym(input$disp_vals)) %>%
pivot_wider(names_from = col, values_from = vals) %>%
gt() %>%
sub_missing(missing_text = "-") %>%
as.data.frame()
rownames(dat_exp) <- dat_exp$row
dat_exp %>%
select(-row) %>%
DT::datatable(selection = list(mode="multiple", target="cell"),
caption = htmltools::tags$caption(paste("Plate", input$plate_no), style="font-weight:bold"),
editable = F,
filter = "none",
options = list(dom='t',
ordering=F,
columnDefs = list(list(width = '70px',
targets = "_all")),
initComplete = JS(
"function(settings, json) {",
"$(this.api().table().header()).css({'background-color': '#cccccc'});",
"}")
),
rownames = T) %>%
formatStyle(0, backgroundColor = "#cccccc")
})
output$table1 <- DT::renderDataTable({
selectedData()
})
```