Good day everyone. so I am encountering huge challenge on Shiny app. I am trying to build a process control model for a bank that determines the completeness or otherwise when data are spooled. It does this by comparing the table features from source to that of destination and tells you that your spool is 'complete', 'incomplete' or 'duplicated'. source is from oracle db and destination is sql db, I therefore connected R to oracle and sql db, and wrote an R script to compare the both tables.
Finally I am building a shiny app to display this comparison, I have written the U.I code which works perfectly well but the server code returns absolutely nothing when ran. Please I need a solution. Here is the code. In this code, I have captured 3 things I want tto see, Spc model, graph for row completeness, and graph for missing fields. Thank you in anticcipation
library(shiny)
library(shinythemes)
library(RODBC)
# Define UI
ui <- shinyUI(fluidPage(
headerPanel(title="STATISTICAL PROCESS CONTROL"),
sidebarLayout(
sidebarPanel(
tags$h3("input:"),
textInput("txt1", "oracle script:", "select * from xxxxxxx"),
textInput("txt2", "sql script:", "SELECT * FROM xxxxxx"),
), # sidebarPanel
submitButton("submit")
),
mainPanel(
tabsetPanel(type = "tab",
tabPanel("spc",tableOutput("spc")),
tabPanel("plot_rowcount",plotOutput("plot_rowcount")),
tabPanel("plot_cell",plotOutput("plot_cell"))
) # mainPanel
), # Navbar 1, tabPanel
) # navbarPage
) # fluidPage
# Define server function
shinyServer(function(input, output) {
SPC= reactive({req(input$txt1,input$txt2)
#SQL_DB_CONNECTION
con=odbcConnect("dsn",uid="sa", pwd="Analytics10$")
on.exit(odbcClose(con), add=TRUE)
sql_db= sqlQuery(con,paste(input$txt1, ";"))
#ORACLE_DB_CONNECTION
con_2 <- odbcConnect("oracle_dsn",uid="DATAANALYTICS", pwd="password10$")
on.exit(odbcClose(con_2), add = TRUE)
odbcQuery(con_2,paste(input$txt2, ";"))
oracle_db = sqlGetResults(con_2, as.is=FALSE, errors=FALSE, max=1000000, buffsize=1,nullstring=NA, na.strings="NA", believeNRows=TRUE, dec=getOption("dec"))
#ROW_COUNT_STATISTICS
source_count= nrow(oracle_db)
Destination_count=nrow(sql_db)
spool_status = if (source_count>Destination_count) {print("incomplete")} else if (source_count<Destination_count) {print("duplicate error")} else {print("complete")}
ROW_COUNT_STATISTICS = data.frame(source_count,Destination_count,spool_status)
#CELL_STATISTICS
missing_fields= length(which(is.na(sql_db)))
No_cell_fields=nrow(sql_db)*ncol(sql_db)
complete_fields= No_cell_fields - missing_fields
percentage_cell_completeness= complete_fields/No_cell_fields *100
CELL_STATISTICS= data.frame(missing_fields,complete_fields,percentage_cell_completeness)
SPC= list(ROW_COUNT_STATISTICS=ROW_COUNT_STATISTICS,CELL_STATISTICS=CELL_STATISTICS)
#PLOTTING A GRAPH
options(scipen=999)
library(ggplot2)
#ROW COUNT PLOT
ROW_COUNT= c(source_count,Destination_count)
Table=c("Source","Destination")
ROW_COUNT_STAT_ggplot=data.frame(ROW_COUNT,Table)
plot_1 = ggplot(ROW_COUNT_STAT_ggplot,aes(x= Table,y=ROW_COUNT)) + geom_point(aes(col=spool_status), size=5) + ggtitle("ROW PLOT")
p= if (source_count>Destination_count) {source_count} else {(Destination_count)}
measurement=coord_cartesian(ylim=c(0,p))
plot_rowcount=plot_1+measurement
#CELL_PLOT
fields= c("Missing_fields","Complete_fields")
Cell_count=c(missing_fields,complete_fields)
CELL_PLOT_ggplot=data.frame(fields,Cell_count)
plot_2= ggplot(CELL_PLOT_ggplot,aes(x= fields,y=Cell_count))+ geom_count(aes(fill=percentage_cell_completeness)) + ggtitle("CELL PLOT")
measurement_2=coord_cartesian(ylim=c(0,No_cell_fields))
plot_cell= plot_2 +measurement_2
})
output$spc <-renderTable{SPC}
}
#Create Shiny object
shinyApp(ui = ui, server = server)