-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.R
executable file
·116 lines (90 loc) · 3.16 KB
/
app.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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
# Initialization -------------------------------------------------------------
## Load libraries. ----
if (!("package:aws.s3" %in% search())) {
suppressMessages(library(aws.s3))
}
if (!("package:shiny" %in% search())) {
suppressMessages(library(shiny))
}
if (!("package:shinythemes" %in% search())) {
suppressMessages(library(shinythemes))
}
if (!("package:shinyjs" %in% search())) {
suppressMessages(library(shinyjs))
}
if (!("package:htmltools" %in% search())) {
suppressMessages(library(htmltools))
}
if (!("package:tidyr" %in% search())) {
suppressMessages(library(tidyr))
}
if (!("package:dplyr" %in% search())) {
suppressMessages(library(dplyr))
}
if (!("package:readr" %in% search())) {
suppressMessages(library(readr))
}
if (!("package:DT" %in% search())) {
suppressMessages(library(DT))
}
## Load S3 keys. ----
Sys.setenv("AWS_ACCESS_KEY_ID" = scan("swrcb-s3-keys.txt",
what = "character",
quiet = TRUE)[1],
"AWS_SECRET_ACCESS_KEY" = scan("swrcb-s3-keys.txt",
what = "character",
quiet = TRUE)[2],
"AWS_DEFAULT_REGION" = scan("swrcb-s3-keys.txt",
what = "character",
quiet = TRUE)[3])
## Load data. ----
s3load(object = "sb-88-deficiencies.RData",
bucket = "dwr-shiny-apps")
## Application Title. ----
app_title <- paste("Searchable SB-88 Measurement Regulation Deficiency List")
# UI ---------------------------------------------------------------------------
ui <- fluidPage( # Begin fluid page.
useShinyjs(),
# Set theme.
theme = shinytheme("cerulean"),
titlePanel(title = div(img(src = "DWR-ENF-Logo-2048.png", height = 60, width = 60), app_title),
windowTitle = app_title),
includeHTML(("./docs/intro-text.html")),
br(),
p(paste0("List last updated: ", gsub("(\\D)0", "\\1", format(compliance_file_date, "%B %d, %Y")), ".")),
# Table.
DTOutput(outputId = "deficiency_table"),
# Download filtered data button.
downloadButton(outputId = "download_filtered",
label = "Download Filtered Data")
) # End fluid page.
# SERVER -----------------------------------------------------------------------
server <- function(input, output, session) { # Begin server.
## Buttons. ----
# Download filtered data.
output$download_filtered <-
downloadHandler(
filename = "Filtered Data.csv",
content = function(file){
write_csv(deficiency_list[input[["deficiency_table_rows_all"]], ],
file,
na = "")
}
)
## Tables. ----
## Demand data table.
output$deficiency_table <- renderDT({
deficiency_list
},
options = list(
columnDefs = list(list(className = 'dt-center', targets = 3:4),
list(targets = c(3:4), searchable = FALSE)),
lengthMenu = c(15, 30, 50),
pageLength = 15
),
filter = "top",
rownames = FALSE)
} # End server.
# APP --------------------------------------------------------------------------
shinyApp(ui = ui,
server = server)