-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.R
More file actions
203 lines (166 loc) · 5.34 KB
/
deploy.R
File metadata and controls
203 lines (166 loc) · 5.34 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
#!/usr/bin/env Rscript
# ==============================================================================
# Deployment Script for Left-Right Associations App
# ==============================================================================
# This script helps deploy the app to shinyapps.io
#
# Prerequisites:
# 1. Install rsconnect: install.packages("rsconnect")
# 2. Configure your shinyapps.io account (see below)
#
# Usage:
# Rscript deploy.R # Deploy the app
# Rscript deploy.R --check # Check dependencies only
# ==============================================================================
# ------------------------------------------------------------------------------
# Configuration
# ------------------------------------------------------------------------------
# App name on shinyapps.io (change if desired)
APP_NAME <- "lr-words-map"
# Required packages for the app
REQUIRED_PACKAGES <- c(
"shiny",
"bslib",
"plotly",
"ggplot2",
"ggrepel",
"dplyr",
"tidyr",
"readr",
"htmltools",
"showtext",
"sysfonts"
)
# Optional packages
OPTIONAL_PACKAGES <- c(
"shinycssloaders" # Loading spinners
)
# ------------------------------------------------------------------------------
# Helper Functions
# ------------------------------------------------------------------------------
check_packages <- function() {
cat("\n=== Checking Required Packages ===\n")
all_ok <- TRUE
for (pkg in REQUIRED_PACKAGES) {
if (requireNamespace(pkg, quietly = TRUE)) {
version <- as.character(packageVersion(pkg))
cat(sprintf(" ✓ %-18s %s\n", pkg, version))
} else {
cat(sprintf(" ✗ %-18s NOT INSTALLED\n", pkg))
all_ok <- FALSE
}
}
cat("\n=== Checking Optional Packages ===\n")
for (pkg in OPTIONAL_PACKAGES) {
if (requireNamespace(pkg, quietly = TRUE)) {
version <- as.character(packageVersion(pkg))
cat(sprintf(" ✓ %-18s %s\n", pkg, version))
} else {
cat(sprintf(" - %-18s not installed (optional)\n", pkg))
}
}
cat("\n=== Checking Deployment Package ===\n")
if (requireNamespace("rsconnect", quietly = TRUE)) {
version <- as.character(packageVersion("rsconnect"))
cat(sprintf(" ✓ %-18s %s\n", "rsconnect", version))
} else {
cat(" ✗ rsconnect NOT INSTALLED\n")
cat("\n To install: install.packages('rsconnect')\n")
all_ok <- FALSE
}
return(all_ok)
}
check_account <- function() {
cat("\n=== Checking shinyapps.io Account ===\n")
if (!requireNamespace("rsconnect", quietly = TRUE)) {
cat(" ✗ rsconnect not installed - cannot check account\n")
return(FALSE)
}
accounts <- rsconnect::accounts()
if (nrow(accounts) == 0) {
cat(" ✗ No shinyapps.io account configured\n")
cat("\n To configure your account:\n")
cat(" 1. Go to https://www.shinyapps.io/admin/#/tokens\n")
cat(" 2. Click 'Show Token' and copy the rsconnect::setAccountInfo() command\n")
cat(" 3. Run that command in R\n")
return(FALSE)
}
cat(sprintf(" ✓ Account configured: %s\n", accounts$name[1]))
return(TRUE)
}
check_data_files <- function() {
cat("\n=== Checking Data Files ===\n")
required_files <- c(
"data/lr_pos_sem_curated.csv",
"data/df_exp_left_curated.csv",
"data/df_exp_right_curated.csv"
)
all_ok <- TRUE
for (f in required_files) {
if (file.exists(f)) {
size <- file.info(f)$size
cat(sprintf(" ✓ %-35s %s\n", f, format(size, big.mark = ",")))
} else {
cat(sprintf(" ✗ %-35s MISSING\n", f))
all_ok <- FALSE
}
}
return(all_ok)
}
deploy_app <- function() {
cat("\n=== Deploying to shinyapps.io ===\n")
if (!requireNamespace("rsconnect", quietly = TRUE)) {
stop("rsconnect package not installed. Run: install.packages('rsconnect')")
}
# Files to deploy
app_files <- c(
"app.R",
"R/",
"www/",
"data/"
)
cat("Deploying app:", APP_NAME, "\n")
cat("Files included:", paste(app_files, collapse = ", "), "\n\n")
rsconnect::deployApp(
appDir = getwd(),
appName = APP_NAME,
appFiles = app_files,
forceUpdate = TRUE
)
}
# ------------------------------------------------------------------------------
# Main
# ------------------------------------------------------------------------------
args <- commandArgs(trailingOnly = TRUE)
if ("--check" %in% args) {
# Check mode - just verify everything is ready
cat("========================================\n")
cat("Deployment Readiness Check\n")
cat("========================================\n")
pkg_ok <- check_packages()
data_ok <- check_data_files()
account_ok <- check_account()
cat("\n========================================\n")
if (pkg_ok && data_ok && account_ok) {
cat("✓ All checks passed! Ready to deploy.\n")
cat(" Run: Rscript deploy.R\n")
} else {
cat("✗ Some checks failed. Please fix the issues above.\n")
}
cat("========================================\n")
} else {
# Deploy mode
cat("========================================\n")
cat("Deploying Left-Right Associations App\n")
cat("========================================\n")
# Run checks first
pkg_ok <- check_packages()
data_ok <- check_data_files()
account_ok <- check_account()
if (!pkg_ok || !data_ok || !account_ok) {
cat("\n✗ Pre-deployment checks failed. Please fix the issues above.\n")
quit(status = 1)
}
# Deploy
deploy_app()
}