Good morning, I'm trying to create a series of graphs(via ggplot) that are reactive based on user selections from the two "
checkboxGroupInput" inputs.
One of the checkboxGroupInput is for the Territory, and the other is to choose the NOB(group1 or group2).
So for example, if the user selects a Territory of "Other", and a NOB of "group1", I would expect the graph to display only those observations that fulfill both conditions, being in "Other" AND "group1". This is working.
What is not working is the following example:
The user selects a Territory of "Other", and a NOB of "group1", and NOB of "group2".
I would expect the graph to display only those observations in "Other" AND in ("group1" OR "group2").
This is the part that is not working.
Right now if I select those 3 choices, it gives me half of the observations that I want to be taken into account.
The CSV I'm using is attached. Could someone with more experience than me(probably most of you), shed some light on why my code doesn't produce the desired outcome?
My code is attached below.
A thousand thanks!
--------------------------------------------------
library("shiny")
library("ggplot2")
##Read in the file from local directory.
data<-read.csv("C:/Users/stang/Desktop/R Directory/Shiny/LR Example.csv", header=TRUE)
##UI side logic
ui<-fluidPage(
headerPanel("Selections:"),
##Separates
sidebarPanel(
checkboxGroupInput("Territory",
label = "Select a Geography",
choices = c("Select All","ALL","LA Orange","Other")),
checkboxGroupInput("Nature",
label = "Select a Nature of Business",
choices = c("group1","group2"))),
mainPanel(
plotOutput("LR_Plot"),
verbatimTextOutput("stats")))
#Server side logic
server<-function(input,output) {
data.new<-reactive({subset(data,data$Territory==input$Territory & data$Nob==input$Nature)})
output$LR_Plot<-renderPlot({
plot1<-ggplot(data.new(), aes(x=Year, y=LossRatio,fill=Year, label = round(LossRatio,2))) +
geom_bar(stat="identity") +
xlab("Years") +
ylab("Loss Ratios") +
ggtitle("LA and Orange County")+
geom_label(aes(fill = Year),colour = "white", fontface = "bold")
print(plot1)
})
output$stats<-renderPrint({summary(data.new())})
}
#Connects the UI to Server
shinyApp(ui=ui,server=server)
-----------------------------------------------