I am making a Shiny app in which there is a unique table and a lot of inputs to modify this table. Since almost all of these inputs are independent and I can classify them into categories, I created several modules, each containing several inputs.
However, since I have a single table to render (i.e only one tableOutput) and since I would like this table to be affected by all modules, I didn't put it in a particular UI module, but I have put one renderTable per server module.
This is a small example reproducing my situation:
library(shiny)
mod_select_ui <- function(id){
ns <- NS(id)
tagList(
selectInput(ns("test_select"), "choose among mtcars", names(mtcars))
)
}
mod_select_server <- function(input, output, session){
output$test_mtcars <- renderTable({
mtcars[[input$test_select]]
})
}
mod_checkbox_ui <- function(id){
ns <- NS(id)
tagList(
checkboxInput(ns("test_checkbox"), "only head of data")
)
}
mod_checkbox_server <- function(input, output, session){
observe({
if(input$test_checkbox){
output$test_mtcars <- renderTable({
head(mtcars)
})
}
})
}
ui <- fluidPage(
mod_checkbox_ui("1"),
mod_select_ui("1"),
tableOutput("test_mtcars")
)
server <- function(input, output, session) {
callModule(mod_select_server, "1")
callModule(mod_checkbox_server, "1")
}
shinyApp(ui, server)
There are several issues in this example. The first one is that nothing is rendered because output$test_mtcars is in server modules and hence, it is expected to have the complementary tableOutput in an UI module. The second one is that I'm not sure that both renderTable will be taken into account.
Is it possible to modify this single tableOutput with several modules? Merging the different UI modules together is not an option (I have separated the inputs in modules precisely because I have a lot of them).
Also asked on StackOverflow