-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.R
More file actions
137 lines (126 loc) · 4.74 KB
/
Copy pathapp.R
File metadata and controls
137 lines (126 loc) · 4.74 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
library(shiny)
library(pool)
library(odbc)
library(tibble)
odbc_args <- list (
drv = odbc(),
dsn = "mars14_datav2",
uid = Sys.getenv("shiny_uid"),
pwd = Sys.getenv("shiny_pwd")
)
repos <- c(CRAN = "https://packagemanager.posit.co/cran/latest")
options(repos = repos)
# odbc_args <- list(odbc(),
# Driver = "PostgreSQL Unicode",
# Server = "PWDMARSDBS1",
# port = 5434,
# Database = "Jon_sandbox",
# uid = Sys.getenv("shiny_uid"),
# pwd= Sys.getenv("shiny_pwd"))
rpost_args <- list(
drv = RPostgres::Postgres(),
host = "PWDMARSDBS1",
port = 5434,
dbname = "mars_data",
user= Sys.getenv("shiny_uid"),
password = Sys.getenv("shiny_pwd")
)
# Define UI for application that draws a histogram
source("sql.R")
ui <- fluidPage(
tabsetPanel(
tabPanel("Test Drivers",
selectInput("platform",
label = "Platform",
choices = c("Windows",
"Linux",
"Posit Connect",
"Workbench")),
selectInput(inputId = "driver",
label = "Driver",
choices = c("ODBC",
"RPostgres")),
numericInput(inputId = "length",
label = "Text Length",
value = 257),
actionButton(inputId = "submit",
label = "Submit"),
actionButton(inputId = "test",
label = "Test"),
numericInput(inputId = "text_length",
label = "Text Length",
value = ""),
numericInput(inputId = "varchar_length",
label = "Varchar Length",
value = ""),
numericInput(inputId = "varchar_1000_length",
label = "Varchar 1000 Length",
value = ""),
textAreaInput(inputId = "text",
label = "text"),
textAreaInput(inputId = "varchar_d",
label = "Varchar Default"),
textAreaInput(inputId = "varchar_1000",
label = "Varchar 1000")
),
tabPanel("drivers",
verbatimTextOutput("drivers")
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
config <- reactive({
# Platfrom data
info <- tibble(
"platform" = input$platform,
"driver" = input$driver,
"length" = input$length
)
})
output$drivers <- renderPrint({
odbc::odbcListDrivers()
})
observeEvent(input$submit, {
# Create a text box based on the legnth
text_block <- strrep("Y", config()$length)
test_id <- NULL
if (config()$driver == "ODBC") {
# Write to values to db and return test_id for ODBC
test <- test_wr(odbc_args, text_block, config()$platform, config()$driver, config()$length)
updateTextAreaInput(inputId = "text", value = test$type_text)
updateTextAreaInput(inputId = "varchar_d", value = test$type_varchar_default)
updateTextAreaInput(inputId = "varchar_1000", value = test$type_varchar)
# Lazy use of super alignment
test_id <<- test$test_id
}
else {
# Write to values to db and return test_id for ODBC
test <- test_wr(rpost_args, text_block, config()$platform, config()$driver, config()$length)
updateTextAreaInput(inputId = "text", value = test$type_text)
updateTextAreaInput(inputId = "varchar_d", value = test$type_varchar_default)
updateTextAreaInput(inputId = "varchar_1000", value = test$type_varchar)
test_id <<- test$test_id
}
})
observeEvent(input$test, {
# Update lengths
updateNumericInput(inputId = "text_length", value = stringr::str_length(input$text))
updateNumericInput(inputId = "varchar_length", value = stringr::str_length(input$varchar_d))
updateNumericInput(inputId = "varchar_1000_length", value = stringr::str_length(input$varchar_1000))
# Ready actual lengths to write DB
char_counts <- tibble(
actual_text_length = stringr::str_length(input$text),
actual_varchar_d_length = stringr::str_length(input$varchar_d),
actual_varchar_1000 = stringr::str_length(input$varchar_1000)
)
# Update records in DB
if (config()$driver == "ODBC") {
test_update(odbc_args, test_id, char_counts)
} else {
test_update(rpost_args, test_id, char_counts)
}
})
}
# Run the application
shinyApp(ui = ui, server = server)