Below, I have some basic code for a shiny app I'm creating. I want to take the user uploaded file, split the dataset into two sections - one based for the first inputted date range and one for the second. Then, compute sums for a different column in the dataset based on those time periods. I can get all of this to work, but my question is if I can somehow use the input$daterange1 and input$daterange2 to title the columns of the datatable, so the user know which sums are associated with which time periods. So below, can I somehow change "Sum 1" and "Sum 2" to the user inputted date ranges?
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
fileInput("file1", "Choose CSV File",
accept=".csv"),
dateRangeInput("daterange1", "Specify First Date Range", start="2016-12-06", end=Sys.Date()),
dateRangeInput("daterange2", "Specify Second Date Range", start=(Sys.Date()-30), end=Sys.Date(),
min="2016-12-06", max=Sys.Date()),
actionButton("submit", "Submit"),
width=3
),
mainPanel(
tabsetPanel(
tabPanel("Sum", DT::dataTableOutput("tab"), downloadButton("dltab", "Download"))
)
)
Server
server <- function(input, output, session) {
observeEvent(input$submit,{
file1=input$file1
if (is.null(file1)){
return(NULL)
}
df<-read.csv(file1$datapath, fileEncoding = "UTF-8-BOM")
df$FAIL<-ifelse(df$OPERATION_STATUS %in% "FAIL",1,0)
df$CATEGORY<-sub("\\s+\\d+", "", df$CRIT_CODE)
df$DATE<-as.Date(df$DATE)
audit<-df
setDT(audit)
audit[,group_o := DATE >= as.Date(input$daterange1[1]) & DATE <= as.Date(input$daterange1[2])]
audit[,group_i := DATE >= as.Date(input$daterange2[1]) & DATE <= as.Date(input$daterange2[2])]
dt<-(audit[, .(
"Sum 1" = sum(OPERATION_STATUS[group_o]),
"Sum 2" = sum(OPERATION_STATUS[group_i]),
"Difference of Sums" = (sum(OPERATION_STATUS[group_o]) - sum(OPERATION_STATUS[group_i])),
keyby = .("Area" = CRIT_CODE)])
output$tab<-DT::renderDataTable({
datatable(dt)
})