-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathglobal.R
More file actions
97 lines (88 loc) · 2.98 KB
/
global.R
File metadata and controls
97 lines (88 loc) · 2.98 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
library(tidyverse)
library(here)
library(deSolve)
library(shiny)
library(bslib)
library(bsicons)
library(shinyhelper)
library(shinyjs)
library(shinyvalidate)
library(shinyWidgets)
library(shinycssloaders)
library(colourpicker)
library(rlang)
library(R.utils)
library(readxl)
library(writexl)
library(plotly)
library(DT)
library(reactlog)
library(shinyFeedback)
library(reshape2)
library(magrittr)
library(reactR)
## HACK NOTE: it is prohibited by box to use library(box), so you must use renv
## to ensure that box is installed on the remote shinyapps.io server. HACK NOTE:
## The box package is requried for using box::use to use reactcharteditor as a
## local module, rather than as a formal, traditional R package installed from
## GitHub.
stopifnot("box" %in% installed.packages())
updateNumericInputs <- function(defaults, session) {
if (any(is.null(dim(defaults)), dim(defaults)[1] != 1)) {
warning("The `defaults` dataframe is not a single row!")
print(defaults) # DONT remove this. It's intentional, not for development.
}
purrr::iwalk(defaults, \(value, inputId) {
updateNumericInput(session, inputId, value = value)
})
}
numericInputWithMathJax <-
function(inputId, rateLabel, initialValue) {
withMathJax(numericInput(
inputId,
sprintf(r"[Rate of %s (\(\%s\))]", rateLabel, inputId),
value = initialValue,
min = 0,
max = 1,
step = 0.01,
width = "300px"
))
}
## Add all of the rules generated by rule function factories to a validator; do
## not apply the functions if the list of inputs and rule vectors is empty
## (ruleList has a length of zero), or if the vector of rules for a single input
## has a length of zero.
##
## This has the side effect of enabling the validator.
##
## Returns the validator invisibly.
addRuleListToValidator <- function(validator, ruleList) {
if (length(ruleList)) {
mapply(
function(inputId, ruleVector) {
validator$add_rule(inputId, sv_required())
if (length(ruleVector)) {
## inputId is intentionally recycled ♺!
mapply(validator$add_rule, inputId, ruleVector)
}
},
names(ruleList),
ruleList
)
}
validator$enable()
invisible(validator)
}
here::i_am("global.R")
## reactcharteditor is a "module" in the box sense, and it is a git submodule
## located in the R/ subfolder of the Shiny application, alongside the scripts
## and other R dependencies which are automatically loaded by Shiny. Shiny does
## not automatically load reactcharteditor, however, because it does not recurse
## through subdirectories of R/ for automatically attaching packages.
options(box.path = here("R"))
box::use(reactcharteditor/R/plotly_editor)
defaultInputValues <- read_xls(here("data/defaultInputValues.xls"),
col_types = c(rep("text", 3),
rep("numeric", 18)),
sheet = "Ashok")
shinyAppDir(here::here()) # and hurrah, we initialize the application!