I'm trying to figure out how to make a ggplot output reactive to the varSelectInput function in the UI of my shiny app. For example, I would like to be able to select two different variables and see them plotted as a function of each other. I've used the flights dataset for this example, ie., select arr_time and dep_delay and see arr_time on the x axis and dep_delay on the y axis.
The DateRangeInput has no function for now, but I would eventually like to be able to filter out the results that are plotted in the ggplot output by month.
library(tidyverse)
library(shiny)
flights <- nycflights13::flights
# Define UI for application
ui <- navbarPage(
"NYC Flights",
tabPanel(
"Flights",
sidebarPanel(
h4("Flight Inputs"),
selectInput(
"Airline_Select",
label = "Select Airline",
choices = flights$Carrier,
selected = TRUE
),
dateRangeInput(
"dates",
label = "Dates",
start = min(flights$Month),
end = max(flights$Month),
min = min(flights$Month),
max = max(flights$Month)
),
varSelectInput(
"X_Axis",
label = "Select Variable 1",
data = flights
),
varSelectInput(
"Y_Axis",
label = "Select Variable 2",
data = flights
),
),
)
)
mainPanel(plotOutput("flights_plot"))
# Define server logic
server <- function(input, output) {
output$flights_plot <- renderPlot({
ggplot(data = flights, aes(x = input$X_Axis, y = input$Y_Axis)) + geom_point()
})
}
# Run the application
shinyApp(ui = ui, server = server)