I created a shiny app which uses the dataframe below to summarize by Dealer showing previous day count of name and last 3 days count of name based on the fact that we are in the most recent date ("2020-01-09").
Now I want to add to every selected period (cell) an indication arrow which will show the trend comparatively to the last time period of the same length, so you would calculate the average number of name for 3 days for example and then in the background calculate the previous 3 days.Same for the previous day. Arrow would indicate if the displayed is higher or lower. I am working based on this answer here.
library(shiny)
library(shinydashboard)
library(dplyr)
name<-c("John","John","John","John","John","John","John")
Dealer<-c("ASD","ASD","ASD","ASD","ASD","ASD","ASD")
Date<-c("2020-01-03","2020-01-04","2020-01-05","2020-01-06","2020-01-07","2020-01-08","2020-01-09")
dataset<-data.frame(name,Dealer,Date)
new<-dataset %>%
mutate(Date = as.Date(Date)) %>%
arrange_all %>%
group_by(Dealer) %>%
summarise(PreviousDay = sum(Date == last(Date) - 1),
PreviousThree = sum(Date %in% (last(Date) - 3) : last(Date)))
new2<-dataset %>%
mutate(Date = as.Date(Date)) %>%
arrange_all %>%
group_by(Dealer) %>%
summarise(PreviousDay = sum(Date == last(Date) - 2),
PreviousThree = sum(Date %in% (last(Date) - 6) : last(Date)))
total<-rbind(new,new2)
sidebar <- dashboardSidebar()
body <- dashboardBody(
fluidRow(box(width = 12, solidHeader = TRUE,
tableOutput("example_table"))
)
)
ui <- dashboardPage(dashboardHeader(title = "Example"),
sidebar,
body
)
server <- function(input, output) {
output$example_table <- renderTable(total)
}
shinyApp(ui, server)