我的代码中收到了这些错误消息,无法理解问题。相信它与dplyr功能有关。
警告:filter_impl错误:结果的长度必须为108,而不是0 126
library(shiny)
library(shinydashboard)
#Single Page Application
ui <- dashboardPage(
#Header section of the application
header <- dashboardHeader(title = "M Dashboard"),
#Sidebar section of the application
sidebar <- dashboardSidebar(
sidebarMenu(
menuItem("M Metrics", tabName = "a"),
menuItem("Raw Data", tabName = "b"),
menuItem("Dropped", tabName = "c")
)
),
#Body of the sidebar contents
body <- dashboardBody(
tabItems(
tabItem(tabName = "a",
fluidRow(
box(uiOutput("facilitylist"),
uiOutput("datelist")
),
box(dataTableOutput("table"))
)
),
tabItem(tabName = "b",
h2("Insert more data here"
)
),
tabItem(tabName = "c",
h2("Insert data here")
)
)
)
)
#Backend server function of the application
server <- function(input, output) {
library(dplyr)
library(shiny)
library(shinydashboard)
library(ggplot2)
library(readr)
x <- data.frame(read_csv("m.csv"))
output$facilitylist <- renderUI({
facilitylist <- sort(unique(as.vector(x$Fac)),decreasing = FALSE)
facilitylist <- append(facilitylist, "TOTAL", 0)
selectizeInput("facilitychoice", "Fac", facilitylist)
})
output$datelist <- renderUI({
datelist <- sort(unique(as.vector(x$Date)), decreasing = FALSE)
datelist <- append(datelist, "TOTAL", 0)
selectizeInput("datechoice", "Date", datelist)
})
data <- reactive({
req(input$facilitychoice)
req(input$datechoice)
if(input$facilitychoice == "TOTAL") {
filt1 <- quote(Fac != "@?><")
} else {
filt1 <- quote(Fac == input$colorchoice)
}
if(input$datechoice == "TOTAL") {
filt2 <- quote(date != "@?><")
} else {
filt2 <- quote(date == input$datechoice)
}
x %>%
filter_(filt1)%>%
filter_(filt2)
})
output$table <- renderDataTable({
data()
})
}
shinyApp(ui, server)
我的数据
Fac Date df df1 df2
HHB 6/1/2018 .5 $100 1
JJK 6/1/2018 .6 $200 2
TOTAL 6/1/2018 1.1 $300 3
HHB 6/2/2018 .4 $50 4
JJK 6/2/2018 .4 $60 5
TOTAL 6/2/2018 .8 $110 9
我相信我可能需要更多地操纵我的数据才能将其转换为更好的格式以进行过滤?以上是数据的一般格式。我想按字符向量Fac过滤,然后按日期向量Date过滤。 Fac中有一个TOTAL行,该行具有该日期所有其他Fac的总和。