这里的第一个问题所以我希望我提供足够的细节。我正在尝试构建一个响应式ggplot来显示给定IAG(年龄组),类别和属性类型的销售额。该图将在主面板中显示,但是,当我更改每个输入字段下的每个列表中的值并点击更新按钮时,图表没有变化。有谁知道这个问题是什么?
另请注意:数据集中的某些属性值确实在两个单词之间有空格,并且在闪亮的应用程序外运行时给了我一些问题...示例:Ranger Woman作为过滤值总是给我一个错误代码。任何具有连字符示例的类别都可以这样说:床单。
library(shiny)
library(lattice, warn.conflicts = FALSE)
library(gridExtra, warn.conflicts = FALSE)
library(RColorBrewer, warn.conflicts = FALSE)
library(readxl, warn.conflicts = FALSE)
library(ggplot2, warn.conflicts = FALSE)
library(data.table, warn.conflicts = FALSE)
library(stats, warn.conflicts = FALSE)
library(dplyr, warn.conflicts = FALSE)
library(lubridate, warn.conflicts = FALSE)
library(readxl, warn.conflicts = FALSE)
da <- read_excel("Order_Export.xlsx")
da$OrderDate = as.Date(da$OrderDate)
da$OrderDate
da$Category = as.factor(da$Category)
da$IAG = as.character(da$IAG)
da$Property = as.factor(da$Property)
da$IAG[da$IAG == "Men, Women"] <- "Adult"
PL_C = da %>% distinct(Property)%>%
arrange(Property,desc(Property))%>%
as.data.frame()
PL_C <- as.list(PL_C$Property)
names(PL_C) <- PL_C$property
C_C = da %>% distinct(Category)%>%
arrange(Category,desc(Category))%>%
as.data.frame()
C_C <- as.list(C_C$Category)
names(C_C) <- C_C$Category
IAG_C = da %>% distinct(IAG)%>%
arrange(IAG,desc(IAG))%>%
as.data.frame()
IAG_C <- as.list(IAG_C$IAG)
names(IAG_C) <- IAG_C$IAG
这是ui.R
ui <- fluidPage(
titlePanel(title="Trends Display"),
sidebarLayout(
sidebarPanel(
actionButton("updt","Update"),
selectInput("PL","Select Property",choices = PL_C),
selectInput("CAT","Select Category",choices = C_C),
selectInput("IAG","Select Age Group",choices = IAG_C)
),
mainPanel(plotOutput("plot2"))
)
)
这是server.R
server <- function(input, output) {
data <- eventReactive(input$updt, {
da %>%
filter(Property == input$PL) %>%
filter(Category == input$CAT) %>%
filter(IAG == input$IAG) %>%
as.data.frame()
da
subset(da,select=c(OrderDate,QtyShipped,Year,Property,Category,IAG))
da$Month = month(as.factor(da$OrderDate))
da$Month = month.abb[da$Month]
da$Month = factor(da$Month, levels=c("Jan", "Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"))
aggregate(QtySent ~ Month+Year, da, sum)
})
output$plot2 <- renderPlot({
ggplot(data(), aes(x=Month, y=QtyShipped, group=factor(Year), colour=factor(Year)))+
geom_line()+
geom_point()
})
}
shinyApp(ui = ui, server = server)