We are suddenly having problems with apps using modules that are stored in the 'R' subdirectory. These are not being sourced at launch, it needs to be forced. The following app does not now work unless lines 3 & 4 are uncommented. We are using shiny 1.7.1 and R 4.1.2. Any advice please?
library(shiny)
# modules <- list.files("R")
# sapply(paste0("R/", modules), source)
ui <- fluidPage(
# Application title
titlePanel("test app"),
sidebarLayout(
sidebarPanel(
selectInput("tabs","Section", choices = c("a"))
),
mainPanel(
uiOutput("main")
)
)
)
server <- function(input, output) {
vals <- reactiveValues(
selected_tab_new = NULL,
selected_tab_old = NULL
)
observeEvent(input$tabs, {
vals$selected_tab_new <- input$tabs
vals$selected_tab_old <- input$tabs
})
observe({
if (!is.null(vals$selected_tab_new)) {
output$main <- renderUI({
rlang::as_function(paste0(vals$selected_tab_new, "UI"))(vals$selected_tab_new)
})
rlang::as_function(paste0(vals$selected_tab_new, "Server"))(vals$selected_tab_new)
}
})
}
# Run the application
shinyApp(ui = ui, server = server)
Module code
ns <- NS(id)
fluidPage(
# shinyjs::useShinyjs(),
fluidRow(
column(width = 12,
h2("Module A")
)
)
)
}
aServer <- function(id) {
moduleServer(id, function(input, output, session, x) {
})
}```