-
Notifications
You must be signed in to change notification settings - Fork 0
/
meta_view_replace.R
60 lines (44 loc) · 1.58 KB
/
meta_view_replace.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
# Function for module UI
meta_view_replace_UI <- function(id) {
ns <- NS(id)
fluidRow(
column(6, downloadButton(ns("export_meta"), "Download Current Meta Data")),
br(),
column(12, fileInput(ns('import_meta'), label = "Select modified Metadata for upload",
multiple = F,
buttonLabel = "Browse or Drop...")),
column(6, actionButton(ns("add_meta"), "Replace existing Metadata")),
column(12, DT::DTOutput(ns("meta_table")))
)
}
# Function for module server logic
meta_view_replace <- function(input, output, session, values) {
#download metadata for user modification
output$export_meta <- downloadHandler(
filename = function() {
paste0("Exported_meta", gsub("-", "_", Sys.Date()), ".csv")
},
content = function(file){
tmpdir <- tempdir()
on.exit(setwd(tmpdir))
print(tmpdir)
write.csv(data.frame(
#values$combined_data@colData@listData
values$combined_meta
),
file, row.names = F)
}
)
# render and update update metadata
proxy <- DT::dataTableProxy("meta_table")
observeEvent(input$add_meta, {
req(input$import_meta)
message(input$import_meta$name)
values$combined_meta <- read.csv(input$import_meta$datapath)
DT::replaceData(proxy, values$combined_meta, resetPaging = FALSE)
shinyCatch(message("Meta data is updated!"))
})
output$meta_table <- DT::renderDT({
DT::datatable(values$combined_meta, editable = TRUE, options = list(scrollX = TRUE), rownames = F)
})
}