I am trying to use modules while developing a shinyApp and I am failing to add a sidebarPanel that change when I change a tabPanel in the mainPanel. For example, when the user is on "Tab1" a h4() element should be added to the sidebarPanel with "Title" and when the user is on "Tab2" the sidebarPanel should show a selectInput(). This is the code I am using. Any idea on what I am doing wrong?
library(shiny)
# Module UI ####
modUI = function(id) {
ns = NS(id)
tabPanel("Dummy Panel",
sidebarPanel("SibeBarPanel",
conditionalPanel("input.ns(mainpanel) == 1",
h4("Title")),
conditionalPanel("input.ns(mainpanel) == 2",
selectInput(ns("s_1"), "Label1", choices = c("A","B")))
),
mainPanel(
tabsetPanel(id=ns("mainpanel"),
tabPanel("Tab1", value = 1),
tabPanel("Tab2", value = 2))))
}
# Module Server ####
modServer <- function(id) {
moduleServer(id, function(input, output, session) {
})
}
server = function(input, output, session) {
modServer("v1")
}
ui = shinyUI(
navbarPage("Dummy",
navbarMenu("This",
modUI("v1")))
)
server = function(input, output, session) {
modServer("v1")
}
shinyApp(ui, server)