Простой вывод таблицы количества работает, когда я меняю даты, но моя таблица суммированных доходов - нет. Я пытался использовать функцию group_by
и reactive
, но безрезультатно.
install.packages(c("shiny","shinydashboard","ggplot2","dplyr","tidyverse","scales","lubridate"))
#not all of these packages may be necesary. They are just the ones I have been playing with
df <- data.frame("Ship Date" = c(2020-01-05,2020-01-06,2020-01-05,2020-01-06,2020-01-05,2020-01-06
,2020-01-05,2020-01-06), "Team" = c("Blue","Blue","Green","Green"
,"Gold","Gold","Purple","Purple"), "Revenue" = c(20,15,17,23
,18,19,17,12))
ui <- fluidPage(
dashboardHeader(title = "Dashboard",titleWidth = 450),
dateRangeInput(
inputId = "daterange",
label = "Select the date range", start = Sys.Date(), end = Sys.Date(), min = min(df$`Ship Date`),
max = max(df$`Ship Date`), format = "yyyy/mm/dd", separator = "-" ),
textOutput("startdate"), textOutput("enddate"), textOutput("range"),
dashboardBody(
fluidRow(
column(width = 3, tableOutput('subdatavt')),
column(width = 3, tableOutput('subdatart'))
)))
server <- function(input, output, session) ({
output$startdate <- renderText({
as.character(input$daterange[1])
})
output$enddate <- renderText({
as.character(input$daterange[2])
})
output$range <- renderText({
paste("Selected date range is ", input$daterange[1], "to", input$daterange[2])
})
#volume by Team
output$subdatavt <- renderTable({
vt = subset(df, df$`Ship Date`>=input$daterange[1] & df$`Ship Date`<= input$daterange[2])
table(vt$Team)
})
#revenue by Team
# here is where I do not know how to go about it. I imagine something to do with the group_by function