У меня есть блестящее приложение ниже, которое сравнивает значения 1-го ряда со значениями 2-го и затем отображает стрелки во 2-м ряду. Как я могу применить это в 1-м ряду вместо 2-го? Я использовал эту логику c здесь
library(shiny)
library(shinydashboard)
library(dplyr)
library(formattable)
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))) %>%
mutate(period = 2)
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))) %>%
mutate(period = 1)
total<-rbind(new,new2) %>%
arrange(period)
sidebar <- dashboardSidebar()
body <- dashboardBody(
fluidRow(box(width = 12, solidHeader = TRUE,
formattableOutput("example_table"))
)
)
ui <- dashboardPage(dashboardHeader(title = "Example"),
sidebar,
body
)
server <- function(input, output) {
output$example_table <- renderFormattable({
improvement_formatter <- formatter("span",
style = x ~ style(font.weight = "bold",
color = ifelse(x-lag(x) > 0, "green",
ifelse(x-lag(x) < 0, "red", "black"))),
x ~ icontext(ifelse(x-lag(x)>0, "arrow-up",
ifelse(x-lag(x)<0, "arrow-down", "")),
x)
)
formattable(total, list(
`PreviousThree` = improvement_formatter,
`PreviousDay` = improvement_formatter)
)
})
}
shinyApp(ui, server)