I have exctracted below mentioned dataframe in R using SQL query.
Query<-paste0("select ID, Date, Value, Result
From Table1
where date(date)>='2018-07-01'
and date(date)<='2018-08-31');")
Dev1<-dbgetquery(database,Query)
Dev1:
ID Date Value Result
KK-112 2018-07-01 15:37:45 ACR Pending
KK-113 2018-07-05 18:14:25 ACR Pass
KK-114 2018-07-07 13:21:55 ARR Accepted
KK-115 2018-07-12 07:47:05 ARR Rejected
KK-116 2018-07-04 11:31:12 RTR Duplicate
KK-117 2018-07-07 03:27:15 ACR Pending
KK-118 2018-07-18 08:16:32 ARR Rejected
KK-119 2018-07-21 18:19:14 ACR Pending
Using above mentioned dataframe, I have created below mentioned pivot dataframe in R.
Value Pending Pass Accepted Rejected Duplicate
ACR 3 1 0 0 0
ARR 0 0 1 2 0
RTR 0 0 0 0 0
And I just want a little help here to trigger those query based on a date range (for example, if one selects some date range on shiny dashboard, data gets automatically updated).
For the sake of simplicity, I have used only 4 columns of dataframe but in my original data I have 30 columns and it's not fitting in the frame on ui
dashboard. Please suggest how to structure the table and color the header.
I am using below mentioned sample code to pass the dataframe.
library(shiny)
library(dplyr)
library(shinydashboard)
library(tableHTML)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
tableHTML_output("mytable")
)
)
server <- function(input, output) {
Date<-Dev1$Date
{
output$mytable <- render_tableHTML( {
Pivot<-data.table::dcast(Dev1, Value ~ Result, value.var="ID",
fun.aggregate=length)
Pivot$Total<-rowSums(Pivot[2:3])
Pivot %>%
tableHTML(rownames = FALSE,
widths = rep(80, 7))
})
}
}
shinyApp(ui, server)
Rrequired sample design: