-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy_serverless_app.R
73 lines (67 loc) · 1.94 KB
/
deploy_serverless_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
# Copy R files from bs
# ========================================
files <- list.files("./bs/R", pattern = ".R", full.names = TRUE)
file.copy(files, "./app/", overwrite = TRUE)
# file <- "./app/MainApp.R"
# content <- readLines(file)
# content <- gsub("uploadUIField",
# "fileInput(\"file\", \"Choose CSV File\",\n accept = c(\n \"text/csv\",\n \"text/comma-separated-values,text/plain\",\n \".csv\"\n )\n ),\n",
# content)
# writeLines(content, file)
# Copy www files from bs
# ========================================
destination_folder <- "./app/www/"
if (!dir.exists(destination_folder)) {
dir.create(destination_folder)
}
file.copy(
from = list.files("./bs/inst/www", full.names = TRUE),
to = destination_folder,
recursive = TRUE, overwrite = TRUE
)
# Create app.R
# ========================================
file.create("./app/app.R", overwrite = TRUE)
con <- file("./app/app.R")
code <- function() {
library(shiny)
library(shinyWidgets)
library(DT)
library(bslib)
library(broom)
library(ggplot2)
library(base64enc)
library(mgcv)
library(RColorBrewer)
library(tidyr)
library(purrr)
library(agricolae)
library(drc)
library(cowplot)
library(MASS)
library(Matrix)
library(shinyjs)
library(equatiomatic)
library(car)
files <- list.files(".", full.names = TRUE)
files <- files[!(basename(files) %in% c("app.R", "www"))]
lapply(files, source)
Sys.setenv(RUN_MODE = "BROWSER")
app <- app()
shiny::shinyApp(app$ui, app$server)
}
code <- body(code) |> deparse()
code <- code[2:(length(code) - 1)]
writeLines(code, con)
close(con)
# Build serverless app
# ========================================
# shinylive::export(
# appdir = "./app",
# destdir = "./app/serverless/",
# quiet = FALSE
# )
shinylive::export("./app", "_site")
# Start app
# ========================================
# httpuv::runStaticServer("./app/serverless/")