-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlaunch_app.R
More file actions
174 lines (148 loc) · 5.48 KB
/
Copy pathlaunch_app.R
File metadata and controls
174 lines (148 loc) · 5.48 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
#!/usr/bin/env Rscript
# Vivid Volcano App Launcher
# This script provides robust browser launching with platform-specific handling
# and fallback mechanisms for when automatic browser opening fails.
cat("🌋 Vivid Volcano Launcher\n")
cat("========================\n\n")
# Check if we're in the right directory
if (!file.exists("app.R") || !file.exists("renv.lock")) {
cat("❌ Error: Not in Vivid Volcano directory\n")
cat("Please navigate to the Vivid-Volcano directory and try again.\n")
quit(status = 1)
}
# Activate renv if available
if (file.exists("renv/activate.R")) {
cat("📦 Activating renv environment...\n")
source("renv/activate.R")
}
# Check essential packages
essential_packages <- c("shiny", "dplyr", "ggplot2", "DT")
missing_packages <- c()
for (pkg in essential_packages) {
if (!requireNamespace(pkg, quietly = TRUE)) {
missing_packages <- c(missing_packages, pkg)
}
}
if (length(missing_packages) > 0) {
cat("❌ Missing essential packages:", paste(missing_packages, collapse = ", "), "\n")
cat("Please run: install.packages(c(", paste0("'", missing_packages, "'", collapse = ", "), "))\n")
quit(status = 1)
}
cat("✅ All essential packages verified\n")
# Detect operating system
get_os <- function() {
if (.Platform$OS.type == "windows") {
return("windows")
} else if (Sys.info()["sysname"] == "Darwin") {
return("macos")
} else {
return("linux")
}
}
# Platform-specific browser launcher
launch_browser <- function(url, os) {
success <- FALSE
if (os == "macos") {
# macOS-specific browser launching with multiple fallbacks
cat("🍎 Detected macOS - using enhanced browser launching...\n")
# Method 1: Try system default browser via open command
tryCatch({
system(paste("open", url), wait = FALSE)
success <- TRUE
cat("✅ Browser launched via 'open' command\n")
}, error = function(e) {
cat("⚠️ 'open' command failed, trying alternatives...\n")
})
# Method 2: Try specific browsers if default failed
if (!success) {
browsers <- c(
"/Applications/Safari.app/Contents/MacOS/Safari",
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
"/Applications/Firefox.app/Contents/MacOS/firefox"
)
for (browser in browsers) {
if (file.exists(browser)) {
tryCatch({
system(paste("'", browser, "'", url), wait = FALSE)
success <- TRUE
cat("✅ Browser launched:", basename(browser), "\n")
break
}, error = function(e) {
# Continue to next browser
})
}
}
}
} else if (os == "linux") {
# Linux browser launching
tryCatch({
system(paste("xdg-open", url), wait = FALSE)
success <- TRUE
cat("✅ Browser launched via xdg-open\n")
}, error = function(e) {
cat("⚠️ xdg-open failed\n")
})
} else if (os == "windows") {
# Windows browser launching
tryCatch({
system(paste("start", url), wait = FALSE)
success <- TRUE
cat("✅ Browser launched via start command\n")
}, error = function(e) {
cat("⚠️ start command failed\n")
})
}
return(success)
}
# Custom browser launching function
custom_launch_browser <- function(appUrl, browser.path = getOption("browser")) {
os <- get_os()
cat("🚀 Starting Vivid Volcano...\n")
cat("📍 App URL:", appUrl, "\n")
cat("🖥️ Operating System:", os, "\n\n")
# Try platform-specific launching
if (launch_browser(appUrl, os)) {
cat("🎉 App should now be opening in your browser!\n")
cat("🛑 To stop the app, press Ctrl+C in this terminal\n\n")
return(TRUE)
}
# Fallback: provide manual instructions
cat("⚠️ Automatic browser launching failed\n")
cat("📋 Manual Instructions:\n")
cat(" 1. Open your web browser\n")
cat(" 2. Navigate to:", appUrl, "\n")
cat(" 3. Or copy and paste this URL into your browser's address bar\n")
cat("🛑 To stop the app, press Ctrl+C in this terminal\n\n")
# Copy URL to clipboard if possible (macOS/Linux)
if (os == "macos") {
tryCatch({
system(paste("echo '", appUrl, "' | pbcopy"))
cat("📋 URL copied to clipboard!\n\n")
}, error = function(e) {})
} else if (os == "linux") {
tryCatch({
system(paste("echo '", appUrl, "' | xclip -selection clipboard"))
cat("📋 URL copied to clipboard!\n\n")
}, error = function(e) {})
}
return(FALSE)
}
# Load shiny library
library(shiny)
cat("🌋 Launching Vivid Volcano...\n\n")
# Run the app with custom browser launching
tryCatch({
runApp(
appDir = "app.R",
host = "127.0.0.1",
port = NULL, # Let shiny choose an available port
launch.browser = custom_launch_browser
)
}, error = function(e) {
cat("❌ Error launching app:", e$message, "\n")
cat("💡 Try running manually with: shiny::runApp('app.R')\n")
quit(status = 1)
}, interrupt = function(e) {
cat("\n👋 Vivid Volcano session ended\n")
quit(status = 0)
})