/
mod_loadData.R
75 lines (65 loc) · 1.68 KB
/
mod_loadData.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
#' @title UI for the data loading module used in safetyGraphicsInit()
#'
#' @param id module id
#' @param domain character vector with domains to be loaded
#'
#' @export
loadDataUI <- function(id, domain=NULL){
ns <- NS(id)
div(
strong(paste(domain,"-")),
textOutput(outputId = ns("name"), inline=TRUE),
actionButton(ns("load_data"), "Load"),
hidden(
actionLink(ns("preview_data"), "Preview")
),
id=ns("wrap")
)
}
#' @title Server for the data loading module used in safetyGraphicsInit()
#'
#' @param domain data domain to be loaded
#' @param input Shiny input object
#' @param output Shiny output object
#' @param session Shiny session object
#'
#' @export
loadData <- function(input, output, session, domain) {
ns <- session$ns
fileSummary <- reactiveVal()
fileSummary("<No Data Loaded>")
observeEvent(input$load_data, {
import_modal(
id = ns("import_modal"),
from = c("env", "file"),
title = paste(domain,"data to be used in application")
)
})
imported <- import_server("import_modal", return_class = "tbl_df")
observe({
req(imported$name(), imported$data())
fileSummary(
paste0(
imported$name(),
" (",
paste(dim(imported$data()),collapse="x"),
")"
)
)
shinyjs::show("preview_data")
})
output$name <- renderText({fileSummary()})
observeEvent(input$preview_data,{
req(imported$data())
showModal(
modalDialog(
title=paste("Preview of '",domain,"' domain:", imported$name()),
DT::renderDataTable({
DT::datatable(imported$data(), escape = FALSE)
}),
size="l"
)
)
})
return(imported$data)
}