I am bulding an app with golem in R . I'm trying to change a TabItem through a button from tabItem (acceuil) to an other tabItem (Rating)
this is Module "Acceuil"
mod_Accueil_ui <- function(id){
ns <- NS(id)
tagList(
actionButton(ns("do"), "Click Me")
)
}
#' Accueil Server Functions
#'
#' @noRd
mod_Accueil_server <- function(id){
mod_Accueil_server <- function(id){
moduleServer( id, function(input,output,session){
ns <- session$ns
observeEvent(input$do, {
updateTabItems(session = session,inputId = "menu",selected = "Rating")
})
})
}
it seems like the mod_Acceuil dosen't recognize the inputId and selected in the updateTabItems. this is the app_ui part
sidebarMenu(id="menu",
tags$head(
menuItem("Rating", tabName = "Rating"),
menuItem("Accueil", tabName = "Accueil")
))
tabItems(
tabItem("Rating",mod_calcul_ui("calcul_ui_1") ),
tabItem("Accueil",mod_Accueil_ui("Accueil_1") )
)
so the problem is when i click the button "Click me" the page does not change
Without testing: Try passing the parent's session to updateItems
. That would require to add the parent's session to the server module:
mod_Accueil_server <- function(id, parent) moduleServer(id,
function(input,output,session) {
ns <- session$ns
observeEvent(input$do, {
updateTabItems(
session=parent, # not the module's session
inputId="menu",selected = "Rating"
)
})
})
and then in the main server function:
server <- function(input,output,session) {
mod_Accueil_server(id="Accueil", parent=session)
# ...
}