I am new to R and am looking for help. I have a csv with two rows (2000, 2010) and two columns (Population 997936 Households 391043 for 2000 and for 2010 1229226 and 474030 respectively). I am trying to create a reactive bar chart using shiny with radio buttons to select either 2000 or 2010 data and cannot get it to work. I know it is related to the way I filter but I cannot figure it out. Here is my code, I would sincerely appreciate any help. As you can see by the comments I have been trying A LOT.
library(shiny)
data <- read.csv("hillsctypop.csv", header = TRUE, sep = ",", stringsAsFactors = FALSE)
ui <- fluidPage(
titlePanel(title = h4("Hillsborough County Population by Census", align="center")),
sidebarPanel(
radioButtons("YEAR", "Select the Census Year",
choices = c("2000", "2010"),
selected = "2000")),
mainPanel(
plotOutput("bar",height = 500))
)
server <- function(input,output){
#year = reactive(data({input$YEAR}))
# filtered <- reactive({
#data %>%
#filter(Type == input$year)
#})
output$bar <- renderPlot({
# barplot(as.matrix(data))
# barplot(data()[,2,4,])
#x <- data[1, ]
color <- c("blue", "red")
barplot(as.integer(data$Population, data$Households),
main = input$YEAR,
ylab="Total",
xlab="Census Year",
names.arg = c("Population", "Households"),
col = color)
#legend("topright", legend = c("Population", "Households"),
# fill = c("Blue", "red"))
})
}
shinyApp(ui=ui, server=server)