-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.R
64 lines (52 loc) · 1.42 KB
/
run.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
# Load required packages
library(dbplyr)
library(dplyr)
library(shiny)
library(DBI)
library(pool)
library(RSQLite)
library(rlang)
# Source all module files
source("R/filter_module.R")
source("R/filter_builder.R")
source("R/group_builder.R")
source("R/summary_builder.R")
source("R/data_fetcher.R")
source("R/column_info_generator.R")
source("R/table_picker.R")
source("R/validation.R")
pool <- dbPool(
drv = RSQLite::SQLite(),
dbname = "database.db"
)
initialize_app <- function(pool) {
message("Initializing application...")
tables <- c("iris", "mtcars")
# Create example database if it doesn't exist
for (table in tables){
if(!table %in% dbListTables(pool) ){
dbWriteTable(pool, table, get(table))
}
}
# Create column info directory if it doesn't exist
if (!dir.exists("column_info")) {
message("creating column_info directory")
dir.create("column_info")
}
# Generate column info for each table
message("Generating column information...")
for (table in tables) {
if (!file.exists(file.path("column_info", paste0("column_info_", table, ".rds")))) {
message(sprintf("Generating column info for table: %s", table))
create_column_info(table, pool)
} else {
message(sprintf("Column info already exists for table: %s", table))
}
}
return(pool)
}
# Initialize the app and get the connection pool
initialize_app(pool)
# Run the app
source("R/app.R")
run_app(pool)