I am working on a shinyapp that I would like to drive the user to different tabs in case certain information/conditions are provided. I'm using the golem framework to construct a robust modular shinyapp. Here is the app_ui.R and app_server.R files that I'm using:
#' The application User-Interface
#'
#' @param request Internal parameter for `{shiny}`.
#' DO NOT REMOVE.
#' @import shiny
#' @noRd
app_ui <- function(request) {
tagList(
# Leave this function for adding external resources
golem_add_external_resources(),
# Your application UI logic
fluidPage(
title = "ShinyApp Modularizada",
shinyjs::useShinyjs(),
# Spacer
tags$div(style = "height: 20px;"),
# Header
tags$p(titlePanel(title = div(
img(src = "", height = "60px", hspace = "50px"),
"Integrated Validation Tool",
img(src = "", height = "60px", hspace = "50px"),
# Useful links
tags$div(style = "margin-right:15px; margin-top: 10px; font-size: 14px;",
downloadLink("manualLink", label = "Manual"),
"-",
a(href="",
target="_blank", "Report new issue"),
align = "right"),
)
)
),
# Tabs
shinydashboard::dashboardBody(
tabsetPanel(
id = "tabs",
tabPanel("Info Module", mod_ivtInfo_ui("ivtInfo")), #modulo de info
tabPanel("Data Validator Information", mod_dataValidatorInfo_ui("dataValidatorInfo")), #modulo de revisor
tabPanel("Data Model Submit", mod_dataModelSubmit_ui("dataModelSubmit")), #modulo de xlsx
tabPanel("Spatial Data Subit", mod_spatialDataSubmit_ui("spatialDataSubmit")), #modulo shp
tabPanel("Data Agreement Submit", mod_dsaSubmit_ui("dsaSubmit")) #modulo dsa/checkbox
)
),
# Footer
fluidRow(
column(12,
tags$div(
style = "text-align: center; font-size: 12px; position: fixed; left: 0; bottom: 20px; width: 100%;",
# Horizontal line
hr(),
# Footer content
HTML("© 2023 IVT | "),
a(href = "", "Twitter"),
HTML(" | "),
a(href = "", "Contact Us")
)
)
)
)
)
}
#' Add external Resources to the Application
#'
#' This function is internally used to add external
#' resources inside the Shiny application.
#'
#' @import shiny
#' @importFrom golem add_resource_path activate_js favicon bundle_resources
#' @noRd
golem_add_external_resources <- function() {
add_resource_path(
"www",
app_sys("app/www")
)
tags$head(
favicon(),
bundle_resources(
path = app_sys("app/www"),
app_title = ""
)
# Add here other external resources
# for example, you can add shinyalert::useShinyalert()
)
}
#' The application server-side
#'
#' @param input,output,session Internal parameters for {shiny}.
#' DO NOT REMOVE.
#' @import shiny
#' @noRd
app_server <- function(input, output, session) {
# Your application server logic
# info server module
mod_ivtInfo_server("ivtInfo")
}
The module for the first tab includes a button that I would like the user to drive to the second tab. Although the button returns the print it doesn't update the data tabSetPanel. Here the module of the first tab
#' ivtInfo UI Function
#'
#' @description A shiny Module.
#'
#' @param id,input,output,session Internal parameters for {shiny}.
#'
#' @noRd
#'
#' @importFrom shiny NS tagList
mod_ivtInfo_ui <- function(id){
ns <- NS(id)
tagList(
shinydashboard::tabItem(
tabName = ns("ivtInfo"),
# Contenedor principal
tags$div(
style = "padding: 0 20px;",
# Download template
tags$div(style = "text-align: center;",
downloadButton("downloadData", label = "Download template", class = "btn-primary")
)
),
# NOT WORKING!!
actionButton(ns("goToDataValidatorInfo"), "Go to Data Validator Information")
)
)
}
#' ivtInfo Server Functions
#'
#' @noRd
mod_ivtInfo_server <- function(id){
moduleServer( id, function(input, output, session){
ns <- session$ns
# goToDataValidatorInfo
observeEvent(input$goToDataValidatorInfo, { #Works but doesnt change tab
shinydashboard::updateTabItems(session = session, inputId = "tabs", selected = "dataValidatorInfo")
print('button clicked')
})
})
}
I think that my issue is not on the module logic but in the definition of the modules on the app_ui.R file (as tabs), but I cannot find the solution!
I've tryed to change the logic on the module and also to define the tabsetpanel using ns() tags for each tab, but it doesn't seem to work. The button responds cause it returns the "print(button clicked)" but it doesn't update the tabsetpanel.