R/mod_switch_maps.R

Defines functions mod_switch_maps_server mod_switch_maps_ui

#' switch_maps UI Function
#'
#' @description [shinyWidgets::actionBttn] to switch which maps tab you're on.
#'
#' @param id,input,output,session Internal parameters for {shiny}.
#'
#' @noRd
#'
#' @importFrom shiny NS tagList
mod_switch_maps_ui <- function(id, label) {
  ns <- NS(id)
  tagList(
    shinyWidgets::actionBttn(
      inputId = ns("switch_maps"),
      label = label,
      style = "jelly",
      color = "success",
      size = "sm"
    )
  )
}

#' switch_maps Server Functions
#'
#' @noRd
mod_switch_maps_server <- function(id, globals) {
  moduleServer(id, function(input, output, session) {
    ns <- session$ns
    observeEvent(input$switch_maps, {
      if (globals$nav() == "global") {
        updateTabsetPanel(globals$session, "nav-page", "usa")
      } else if (globals$nav() == "usa") {
        updateTabsetPanel(globals$session, "nav-page", "global")
      }
    })
  })
}

## To be copied in the UI
# mod_switch_maps_ui("switch_maps_ui_1")

## To be copied in the server
# mod_switch_maps_server("switch_maps_ui_1")
appliedbinf/c19r-app documentation built on April 27, 2023, 11:54 p.m.