-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.R
More file actions
252 lines (215 loc) · 7.9 KB
/
app.R
File metadata and controls
252 lines (215 loc) · 7.9 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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
################################################################################
# ___________________________________________________ #
# SpecTraits #
# Spectra - Traits #
# A Shiny Application for prediction leaf traits #
# from spectra models using R #
# Author: J. Antonio Guzmán Q. #
# ___________________________________________________ #
# #
################################################################################
# Name convention for scripts
# _input: all user information that serve as input
# _import: functions to read files
# _frame: all data.frames created
# _plot: scripts to render figures in ui
# _figure: all figures created as outputs
# _go: names to link between panels
# _action: name for bottom activation
# _panel: Major UI panels of visualization
# _aux: Auxiliary functions
################################################################################
# Libraries --------------------------------------------------------------------
################################################################################
# Define packages
packages <- c("shiny", "shinycssloaders",
"bslib", "data.table", "dplyr",
"pls", "DT", "here", "reshape2", "magrittr",
"ggplot2", "rlang", "caret", "zip", "kableExtra",
"spectrolab", "knitr", "rmarkdown", "quarto",
"signal", "CWT")
# Install packages not yet installed
installed_packages <- packages %in% rownames(installed.packages())
if (any(installed_packages == FALSE)) {
install.packages(packages[!installed_packages], dependencies = TRUE)
}
# Check rhdf5
if(!("ccrtm" %in% installed.packages())) {remotes::install_github("MarcoDVisser/ccrtm")}
# Required packages
sapply(c(packages, "ccrtm"), require, character.only = TRUE)
################################################################################
# Options ----------------------------------------------------------------------
################################################################################
# File size upload
options(shiny.maxRequestSize= 1000*1024^2)
options(shiny.deprecation.messages=FALSE)
################################################################################
# Source of helpers ------------------------------------------------------------
################################################################################
# Home access functions
source("R/home_panel.R")
source("R/predict_panel.R")
source("R/build_panel.R")
source("R/preprocessing_panel.R")
source("R/about_panel.R")
# Functions for predict panel
source("R/predict/spectra_import.R")
source("R/predict/spectra_plot.R")
source("R/predict/method_input.R")
source("R/predict/run_action.R")
#source("R/predict/plsr_traits_predict_aux.R")
source("R/predict/rtm_traits_predict_aux.R")
source("R/predict/predicted_plot.R")
source("R/predict/traits_import.R")
source("R/predict/validation_plot.R")
source("R/predict/traits_export.R")
source("R/predict/info_frame.R")
# Functions for build panel
source("R/build/trait_selector_input.R")
source("R/build/build_import_plot.R")
source("R/build/split_input.R")
source("R/build/run_split_action.R")
source("R/build/split_action_plot.R")
source("R/build/press_input.R")
source("R/build/run_press_action.R")
source("R/build/pls_permutation_press_aux.R")
source("R/build/press_action_plot.R")
source("R/build/find_optimal_ncomp_aux.R")
source("R/build/final_optimal_input.R")
source("R/build/run_plsr_action.R")
source("R/build/pls_permutation_coef_aux.R")
source("R/build/vip_aux.R")
source("R/build/pls_summary_aux.R")
source("R/build/confidence_interval_aux.R")
source("R/build/coefficients_plot.R")
source("R/build/build_plsr_predict.R")
source("R/build/plsr_predict_aux.R")
source("R/build/model_performance_aux.R")
source("R/build/performance_plot.R")
source("R/build/build_export.R")
source("R/build/plsr_traits_predict_aux.R")
# Functions for pre-processing
source("R/preprocessing/resample_input.R")
source("R/preprocessing/run_resample_action.R")
source("R/preprocessing/resampled_export.R")
source("R/preprocessing/smoothing_input.R")
source("R/preprocessing/run_smoothing_action.R")
source("R/preprocessing/transformation_input.R")
source("R/preprocessing/run_transformation_action.R")
source("R/preprocessing/processed_export.R")
source("R/preprocessing/preprocessing_plot.R")
# Functions for data
source("R/data_panel.R")
source("R/data/data_config.R")
################################################################################
# App---------------------------------------------------------------------------
################################################################################
# ------------------------------------------------------------------------------
# Define UI for application
ui <- page_navbar(
title = "SpecTraits",
id = "main_tabs",
nav_spacer(),
theme = bs_theme(bootswatch = "yeti",
primary = "#005F5F"),
bg = "#005F5F",
# Custom CSS for Browse buttons
tags$head(
tags$style(HTML("
/* Style all Browse buttons to match app theme */
.btn-file {
background-color: #005F5F !important;
border-color: #005F5F !important;
color: white !important;
}
.btn-file:hover {
background-color: #004848 !important;
border-color: #004848 !important;
color: white !important;
}
/* Also style the file input browse button directly */
input[type='file']::file-selector-button {
background-color: #005F5F;
border: 1px solid #005F5F;
color: white;
padding: 6px 12px;
border-radius: 4px;
cursor: pointer;
}
input[type='file']::file-selector-button:hover {
background-color: #004848;
border-color: #004848;
}
"))
),
nav_panel(
"Home",
home_panel_ui("home")
),
nav_panel(
"Predict",
predict_panel_ui("predict")
),
nav_panel(
"Build",
build_panel_ui("build")
),
nav_panel(
"Pre-process",
preprocessing_panel_ui("preprocessing")
),
# nav_panel(
# "Data",
# data_panel_ui("data")
# ),
nav_panel(
"About",
about_panel_ui("about")
),
nav_item(
tags$a(icon("github"),
"SourceCode",
href = "https://github.com/ASCEND-BII/SpecTraits",
target = "_blank")
)
)
# ------------------------------------------------------------------------------
# Define server logic required to draw a histogram
server <- function(input, output, session) {
go_to_predict <- reactiveVal(FALSE)
go_to_build <- reactiveVal(FALSE)
go_to_prepro <- reactiveVal(FALSE)
go_to_data <- reactiveVal(FALSE)
home_panel_server("home", go_to_predict, go_to_build, go_to_prepro)
predict_panel_server("predict")
build_panel_server("build")
preprocessing_panel_server("preprocessing")
data_panel_server("data")
observeEvent(go_to_predict(), {
if (go_to_predict()) {
updateTabsetPanel(session, "main_tabs", selected = "Predict")
go_to_predict(FALSE)
}
})
observeEvent(go_to_build(), {
if (go_to_build()) {
updateTabsetPanel(session, "main_tabs", selected = "Build")
go_to_build(FALSE)
}
})
observeEvent(go_to_prepro(), {
if(go_to_prepro()) {
updateTabsetPanel(session, "main_tabs", selected = "Pre-process")
go_to_prepro(FALSE)
}
})
# observeEvent(go_to_data(), {
# if(go_to_data()) {
# updateTabsetPanel(session, "main_tabs", selected = "Data")
# go_to_data(FALSE)
# }
# })
}
# ------------------------------------------------------------------------------
# Run the application
shinyApp(ui = ui, server = server)