I’m fairly new to Shiny and am running into the following issue where i can’t find a variable
enter image description here
This is my UI…
ui <- {
fluidPage(
titlePanel("ABR Dashboard"),
tabsetPanel(
tabPanel("Time Series",
sidebarLayout(
selectInput(inputId = "Date1",
label = "Select Date",
choices = seq(from = as_date(now())-16, to = as_date(now())-1, by = "day")
),
selectInput(inputId = "Metric1",
label = "Which Metric",
choices = c("Login","Queue"))
)
),
mainPanel(
plotOutput("distPlot1")
)
)
)
}
This is my server…
server <- function(input, output, session) {
MyDT <- reactive({
AbrQuery <- "
SELECT
*
FROM SQ_ML_MODEL.dbo.DataSci_ABR_Preds_Vs_Actuals_updated
"
SecretValuesLst <- GetSecret(Debug = TRUE)
print(SecretValuesLst)
print(SecretValuesLst$SERVER)
#===============================================================================
connectionString <- paste0(
"Driver={ODBC Driver 18 for SQL Server};Server=",SecretValuesLst$SERVER,
";Database=",SecretValuesLst$DATABASE,
";UID=",SecretValuesLst$UID,
";PWD=",SecretValuesLst$PWD,
";TrustServerCertificate=yes;",
sep="")
DbCon <- RODBC::odbcDriverConnect(connectionString)
print(DbCon)
#===============================================================================
DataOutput <- RODBC::sqlQuery(DbCon, query = AbrQuery)
DataOutput
#===============================================================================
###
message("render_app_data: Prepare Data n")
# RawAbrData
# str(RawAbrData)
VizAbrData <- melt.data.table(DataOutput[, .(MinuteOfDay,
AgentCategory,
Queue,
Login,
Tier,
Abr_Actuals,
Abr_Preds,
Abr_Diff)],
id.vars = c("MinuteOfDay",
"AgentCategory"))
VizAbrData
# VizAbrData[, .N, by = variable]
# VizAbrData[variable == "Login"]
VizAbrData[, AsOfDate := as_date(MinuteOfDay)]
# VizAbrData[, .N, by = AsOfDate]
# WhichDates <- VizAbrData[order(-AsOfDate)][, unique(AsOfDate)][1:14]
# WhichDates
# VizAbrData <- VizAbrData[AsOfDate %in% WhichDates]
# VizAbrData
VizAbrData$value[is.na(VizAbrData$value)] <- 0
# VizAbrData
library(hms)
VizAbrData[, MinuteOfDay_TIME := as_hms(MinuteOfDay)]
mydat <- VizAbrData
mydat[, AsOfDate := as.Date(AsOfDate)]
mydat[, variable := as.character(variable)]
#WhichDates <- mydat[, .N, by = AsOfDate][order(-AsOfDate)][1:10, AsOfDate]
#WhichVariables <- mydat[, .N, by = variable][order(-variable)][1:10, variable]
})
output$distPlot1 <- renderPlot({
filtered_data_1 <- reactive({
subset(MyDT,
AsOfDate %in% seq(from = as_date(now())-16, to = as_date(now())-1, by = "day") &
variable %in% c("Login","Queue"))
})
ggplot(data = filtered_data_1(),
aes(x = MinuteOfDay,
y = value)) +
geom_point(stat = "identity", col = "black") +
geom_line(stat = "identity", linewidth = 1.6, col = "red") +
labs(x = "MinuteOfDay", y = input$Metric1) +
ggtitle(paste0("Time Series: ", input$Metric1, sep = "")) +
theme(
plot.title = element_text(size=16, face= "bold", colour= "black", hjust = 0.5, margin = margin(t=10,b=-20)),
axis.title.x = element_text(size=16, face="bold", colour = "black"),
axis.title.y = element_text(size=14, face="bold", colour = "black"),
axis.text.x = element_text(size=14, face="bold", colour = "black"),
axis.text.y = element_text(size=14, face="bold", colour = "black"), # bold
strip.text.x = element_text(size = 14, face="bold", colour = "black" ),
strip.text.y = element_text(size = 14, face="bold", colour = "black"),
axis.line.x = element_line(color="black", size = 0.3),
axis.line.y = element_line(color="black", size = 0.3),
panel.border = element_rect(colour = "black", fill=NA)
) +
theme_classic()
})
}
I’ve seen posts where people say to add req() to the server section, but just looking for a clear sol8tion
Tried req, passing variables to the server, etvc