Hi all,
I am building an app using Shiny IO. This is how my data looks like
OrderDate Company TotalOrder ApprovalID State
I am letting users filter for OrderDate and Company using reactive. However, I want to aggregate that filtered data on ApprovalID, State and various other columns that I have to see within the chosen timeframe and company how does the total order vary by these factors
Here is my code:
if (interactive()) {
ui = fluidPage(theme = 'custom.css',
h2("X",id="big-heading"),
titlePanel(" ",windowTitle = "X"),
tabsetPanel(
tabPanel("Plot", fluid = TRUE,
sidebarLayout(
sidebarPanel(id = 'sidebar',
dateRangeInput("dateinput","Selects Dates",start = Sys.Date()-30,end = Sys.Date()),
selectInput("companyinput", "Select Comp", choices=choices1,multiple = TRUE,selected = NULL)
),
mainPanel(fluidRow(
splitLayout(cellWidths = c("50%", "50%"), plotOutput("coolplot"), plotOutput("coolplot3")),
plotOutput("coolplot1"),
textOutput("resultX")
)
)
),
),
tabPanel("Summary", fluid = TRUE,
sidebarLayout(
sidebarPanel(id = 'sidebar',
dateRangeInput("dateinput","Selects Dates",start = Sys.Date()-30,end = Sys.Date()),
selectInput("companyinput", "Select Comp", choices=choices1,selected = NULL)
),
mainPanel(
textOutput("resultY")
)
)
)
)
)
server = function(input, output) {
filtered <- reactive({
if(is.null(input$companyinput)){
bc3 %>%
filter(as.Date(OrderDate) > input$dateinput[1],
as.Date(OrderDate) >= input$dateinput[2],
)
}
else{
bc3 %>%
filter(as.Date(OrderDate) > input$dateinput[1],
as.Date(OrderDate) >= input$dateinput[2],
CompanyNameID == input$companyinput
)
}
})
"Is there a way I can create a data frame of the filtered data so I can manipulate and aggregate as and when I want
output$results <- renderTable({
filtered()
},spacing = "s",align = 'c',digits = 0,bordered = TRUE,hover = TRUE,width = "auto")
output$coolplot <- renderPlot({
df <- cbind(filtered$BuyerID,filtered$DocTotalOrder)
ag <- aggregate(df,by = df$BuyerID,fun = sum)
ggplot(filtered(), aes(y=DocTotalOrder, x=BuyerID,label = DocTotalOrder)) +
geom_bar(stat="identity",fill = "#FF9999")
})
output$coolplot1 <- renderPlot({
ggplot(filtered()) +
stat_summary(aes(x = BuyerID, y = DocTotalOrder),
fun.y = function(x) sum(x),
geom = "bar")
})
output$coolplot3 <- renderPlot({
ggplot(filtered(), aes(y=DocTotalOrder, x=BuyerID)) +
geom_bar(stat="identity",fill = "#004701")
})
}
# Run the application
shinyApp(ui = ui, server = server)
}