I'm starting to build out more complex Shiny apps and am trying to figure out modules to help with my workflow. I have build some smaller modules that work, but this current one has the page formatting I want, but the desired table doesn't appear when I run the module. What am I missing?
library(shiny)
library(shinydashboard)
library(shinyWidgets)
library(nycflights13)
df <- nycflights13::flights
# Flight module ----
depart_ui <- function(id) {
tagList (
selectInput (NS(id, "depart"), "Departure", choices = c("All", sort(unique(df$origin))))
)
}
dest_ui <- function(id) {
tagList (
selectInput (NS(id, "dest"), "Destination", choices = c("All", sort(unique(df$dest))))
)
}
flight_server <- function(id) {
moduleServer(id, function(input, output, session) {
# data <- reactive (df %>%
# select (year, month, day, origin, dest) %>%
# dplyr::filter (origin == input$depart) %>%
# dplyr::filter (origin == input$dest)
# )
data <- reactive (df)
output$flights <- DT::renderDataTable({
data()
})
})
}
flight_app <- function() {
ui <- fluidPage(
fluidRow (
HTML("<h2><center>Origins and Destinations</center></h2>")
),
fluidRow(
column(
width = 6,
HTML("The following table shows the flight origins and destinations. ")
),
column (
depart_ui("depart"),
width = 2
),
column (
dest_ui("dest"),
width = 2
)
),
fluidRow(
dataTableOutput("flights")
)
)
server <- function(input, output, session) {
flight_server("flights")
}
shinyApp(ui, server)
}
flight_app ()