Apologies if this is a simple question. I have been trying for a while to figure this out and I am still confused. I am building a simple shiny app for my class and still cannot figure out or understand how I connect my inputs to the actual graph output so that when I select something the graph changes.
What I am working on is a basic Plane Crash data set and trying to show how crashes have changed over time etc. Below is my code. I can get the inputs set up and the graph output but I don't know where I'm missing the part that connects the two.
crash_year <- c(2016,2016,2015,2014,2015,2015)
amateur_built <- c('yes','yes','no','no','no','no')
ac_type <- c('Airplane','Airplane,'Airplane,'Helicopter','Airplane','Unknown')
dt <- data.table(crash_year,amateur_built,ac_type)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
selectInput(inputId = "ac", label = "Aircraft Type:",
choices = c('Airplane','Helicopter','Glider','Balloon','Unknown','Gyroplane','Weight-Shift','Powered Parachute','Ultralight','Rocket','Gyrocraft','Powered-Lift','Blimp'),
selected = 'Airplane'),
selectInput(inputId = 'pro_am', label = "Amateur Built?",
choices = c('Yes','No'),
selected = 'Yes')
),
mainPanel(
plotOutput(outputId = 'bar'),
dataTableOutput(outputId = 'data'),
br()
)
)
)
server <- function(input, output, session) {
#create barchart object
output$bar <- renderPlot({
ggplot(data = dt, aes(x=crash_year,y=input$ac)) +
geom_bar(stat = "identity")
})
}
shinyApp(ui, server)