I am currently trying to modulate my brilliant application based on this tutorial . In my actual application, I have two selectInputthat allow the user to select the first and last quarter-final date, based on which some statistics are calculated for a certain data set. Since the available dates at the end of the quarter depend on the actual data set and different data sets are used, I dynamically pass the parameter choices selectInputto the server functions. The process is as follows:
- Create objects
selectInputdynamically conditionally on the available data end dates. - Use the selected quarter dates to limit the specific data set accordingly.
I do this over and over in my application for different data sets, so now I want to create a module. However, I am struggling to get the selected quarter-end dates that I could use to limit my data set.
Below is a small application that illustrates my problem.
part of the application.
source("module.R")
ui <- fixedPage(
selectQuartersUI("test"),
textOutput("summary")
)
server <- function(input, output, session) {
testValues <- callModule(selectQuarters, "test", 1:10)
output$summary <- renderText({
sprintf(paste0("Start: ", testValues(), collapse = "_"))
})
}
shinyApp(ui, server)
module.R part
selectQuartersUI <- function(id) {
ns <- NS(id)
fluidRow(
column(3, htmlOutput(ns("startQuarter"))),
column(3, htmlOutput(ns("endQuarter")))
)
}
selectQuarters <- function(input, output, session, vec_dates) {
vec_dates <- sort(unique(vec_dates))
output$startQuarter <- renderUI({
ns <- session$ns
selectInput(ns("startQuarter"), "Start:", vec_dates[1:(length(vec_dates)-1)],
multiple = FALSE,
selected = max(vec_dates[1:(length(vec_dates)-1)]))
})
output$endQuarter <- renderUI({
ns <- session$ns
selectInput(ns("endQuarter"), "End:", vec_dates,
multiple = FALSE,
selected = max(vec_dates))
})
return(list(reactive({input$startQuarter}),
reactive({input$endQuarter})))
}
The wrong part is to return the selected quarter dates to testValues, but I'm trying to figure out why.