Below is my code in it's entirety, which of course includes the above snippets.Â
df <- read.csv("C:/Users/stang/Desktop/R Directory/Shiny/LR Example.csv", header=TRUE)
territoryfactor<-as.factor(df$Territory)
graphdata<-data.frame(year=c(df$Year),lossratio=c(df$LossRatio), territory=territoryfactor)
graphdata
str(graphdata)
OTHERdata<-subset(graphdata,territory=="Other")
LAORANGEdata<-subset(graphdata, territory=="LA Orange")
ALLdata<-subset(graphdata, territory=="Other" | territory =="LA Orange")
##For the first button, I'm just using OTHERdata
##For the second button, I'm just using LAORAGENdata
##For the third button, I'm just using ALLdata
##UI Code, creating 3 buttons from Radio Button inputÂ
ui<-(fluidPage(
 sidebarLayout(
  sidebarPanel(
Â
   radioButtons("col","Switch Plot",
          choices = c("Other", "LA Orange","All"),
          selected = "Other")
  ),
  mainPanel(
   conditionalPanel(
    condition = "input.col == 'Other'", plotOutput("hist1")),
   conditionalPanel(
    condition = "input.col == 'LA Orange'", plotOutput("hist2")),
   conditionalPanel(
    condition = "input.col == 'All'", plotOutput("hist3"))
  )
 )
))
 Â
  Â
 Â
 Â
##Server Code, once each button is clicked, it would produce a bar graph of the applicable subsetted data set above.
##(i.e., graph 1 uses OTHERdata, graph 2 uses LAORANGEdata, graph 3 uses ALLdata)
server<-function(input,output,session){Â
 Â
 Â
 output$hist1 <- renderPlot({
 Â
 Â
  dat2<-reactive({
   OTHERdata[which(OTHERdata$territory == input$col),]
 })
 Â
 plot1<- ggplot(dat2(), aes(x=year, y=lossratio,fill=year, label = round(lossratio,2))) +
  geom_bar(stat="identity") +
  xlab("Years") +
  ylab("Loss Ratios") +
  ggtitle("All Other States")+
  geom_label(aes(fill = year),colour = "white", fontface = "bold")
   Â
 Â
})
}
 Â
 Â
 Â
shinyApp(ui = ui, server = server)