Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 如何将汇总表连接到闪亮应用程序中的日期范围?_R_Shiny_Dplyr_Tidyverse_Shinydashboard - Fatal编程技术网

R 如何将汇总表连接到闪亮应用程序中的日期范围?

R 如何将汇总表连接到闪亮应用程序中的日期范围?,r,shiny,dplyr,tidyverse,shinydashboard,R,Shiny,Dplyr,Tidyverse,Shinydashboard,当我更改日期时,计数的简单表输出有效,但我的合计收入表无效。我曾尝试使用group\u 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

当我更改日期时,计数的简单表输出有效,但我的合计收入表无效。我曾尝试使用
group\u 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
install.packages(c(“shiny”、“shinydashboard”、“ggplot2”、“dplyr”、“tidyverse”、“scales”、“lubridate”))
#并非所有这些软件包都是必需的。他们正是我一直在玩的人

这就是你要找的吗

library(lubridate)
library(dplyr)
library(shiny)
library(shinydashboard)

df <- tibble("ShipDate" = as.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$ShipDate),
    max = max(df$ShipDate), 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 = df %>% filter(ShipDate >= input$daterange[1],
                       ShipDate <= input$daterange[2]) %>% 
      group_by(Team) %>% 
      summarise(Revenue = sum(Revenue), n=n()) %>% 
      na.omit
  })
})

shinyApp(ui = ui, server = server)
库(lubridate)
图书馆(dplyr)
图书馆(闪亮)
图书馆(shinydashboard)

df我需要的是每个团队的总收入。这很容易做到,但我无法让它“附加”到日期过滤器。无论我如何更改过滤器,收入值都保持不变@motchI尝试使用
output$ro%groupby(Team)%%>%summary(Revenue=sum(Revenue),n=n())%%>%na.omit})
但不起作用。我不知道为什么这样做对您不起作用,可能是您忘记删除表(vt$Team)。我编辑了我想你想要的答案谢谢你@motch。我搞砸了。你的代码是正确的。