I ran the following code and it filters the plotted data just as expected. When I set Class to A and Product Family to Product Family 1, I get a single plot with three points. The important change is that I used & to connect the filter conditions. I also increased the point size just so I could see the markers better and I commented out the loading of packages that are not needed for this example.
Note that I commented out the closing back tics of the chunks to preserve the formatting. You will have to remove the # characters.
---
title: "ABC INC"
runtime: shiny
output:
flexdashboard::flex_dashboard:
orientation: rows
vertical_layout: scroll
source_code: embed
theme: cosmo
---
```{r setup, include=FALSE}
library(flexdashboard)
#library(readxl)
library(tidyverse)
library(ggplot2)
#library(plotly)
#library(reshape)
```
```{r}
df <- structure(list(Class = c("A", "A", "A", "A", "A", "B", "B", "B",
"B", "B"), Product = c("Product 1", "Product 2", "Product 3",
"Product 4", "Product 5", "Product 1", "Product 2", "Product 3",
"Product 4", "Product 5"), `Product Family` = c("Product Family 1",
"Product Family 1", "Product Family 1", "Product Family 2", "Product Family 3",
"Product Family 1", "Product Family 1", "Product Family 1", "Product Family 2",
"Product Family 3"), `Month Ending Date` = structure(c(1420070400,
1422748800, 1425168000, 1427846400, 1430438400, 1420070400, 1422748800,
1425168000, 1427846400, 1430438400), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), Spend = c(95, 93, 98, 100, 93, 95, 93, 98,
100, 93)), row.names = c(NA, -10L), class = c("tbl_df", "tbl",
"data.frame"))
df <- as.data.frame(df)
colnames(df) <- gsub(" ","_",colnames(df))
df$Month_Ending_Date <- as.Date(df$Month_Ending_Date)
```
Performance
=======================
Filters {.sidebar}
------------------
```{r}
selectInput("Plot",h5("Performance"),choices = c("","Plot"))
selectInput("Class",h5("Class"),choices = c("All",levels(factor(df$Class))),multiple = TRUE)
selectInput("ProductFamily",h5("Product Family"),choices =c("All",levels(factor(df$Product_Family))),multiple = TRUE)
```
Output
------------------
### Chart A {data-heigh=500}
```{r}
plotOutput("graph",height = "5000px",width = "1000px")
sel_data <- reactive({
df[df$Class %in% input$Class & df$Product_Family %in% input$ProductFamily,]
})
graph <- reactive({
if (input$Plot == "Plot" && input$Class == "All" && input$ProductFamily == "All") {
ggplot(df,aes(x=Month_Ending_Date,y=Spend,color = Product))+ geom_point() +
facet_wrap("Product_Family") + theme(legend.position = "none") +
theme(legend.position = "none")
} else {
ggplot(sel_data(),aes(x=Month_Ending_Date,y=Spend,color =
Product)) + geom_point(size = 6) + facet_wrap("Product_Family") +
theme(legend.position = "none") +
geom_text(data = sel_data(), aes( x = Month_Ending_Date,
label = round((Spend/1000000),2)),
size = 3, angle = 45, color = "black", vjust=-0.25) +
theme(legend.position = "bottom")
}
})
output$graph <- renderPlot({
graph()
})
```