I would like to create a shiny app with tabs using a modular approach, but I would like some tab selections to show the same page/collection of uiobjects as each other. Importantly, I don’t want to create the same page/module/uiobjects twice and match the state of the iuobjects between each instance. I have a reprex below which currently creates the same module twice with the same id (I think all I’ve achieved here is bad coding practice!). Is there a way that mod_test_ui("test_1")
can be created once and displayed when either tab1_DROPDOWN
or tab2_DROPDOWN
is selected?
library(shiny)
library(plotly)
library(shinythemes)
mod_test_ui <- function(id){
ns <- NS(id)
tagList(
fluidRow(
h2("MODULE1"),
selectInput(inputId = ns("dropdown"),
label = "DROPDOWN",
choices = c("aa","bb"),
selected = "aa"
),
textOutput(ns("text"))
)
)
}
mod_test_server <- function(id, df, vbl, threshhold) {
moduleServer(id, function(input, output, session) {
output$text <- renderText({input$dropdown})
})
}
ui <- fluidPage(
navbarPage("",
navbarMenu('menu 1',
tabPanel("tab1_DROPDOWN",
fluidRow(
mod_test_ui("test_1")
)
),
tabPanel("tab2",
fluidRow(
h2("things and stuff")
)
)
),
navbarMenu('menu 2',
tabPanel("tab1",
fluidRow(
h2("Blah blah")
)
),
tabPanel("tab2_DROPDOWN",
fluidRow(
h2("Box Plot"),
mod_test_ui("test_1")
)
)
)
)
)
server <- function(input, output, session) {
mod_test_server("test_1")
}
shinyApp(ui, server)