#' Switch module UI
#'
#' @description A switch module UI that can accept dynamic inputs on the server-side
#' declaration
#' @param id is unique ID associated with the switch for the UI namespace
#'
#' @return HTML UI code for a shiny application
#'
#' @importFrom shiny uiOutput
#' @export
switch_ui <- function(id) {
ns <- NS(id)
uiOutput(ns("switch"))
}
#' Switch module Server
#'
#' @description A switch module UI that can accept dynamic inputs on the server-side
#' declaration
#' @param input list of inputs used in the shiny application session
#' @param output list of outputs used the shiny application session
#' @param session The shiny app session object
#' @param label The label of the \code{switchInput} function. Converted to reactive later for enabling encapsulation
#' @param onLabel The label of the \code{switchInput} function's on position.
#' @param offLabel The label of the \code{switchInput} function's off position.
#' @param value The default value for the \code{switchInput} function.
#' @param on The on value for the \code{switchInput} choices.
#' @param off The off value for the \code{switchInput} choices.
#'
#' @return Numeric or Character. Radio buttons selected value
#'
#' @importFrom shiny renderUI
#' @importFrom shinyWidgets switchInput
#' @export
switch_server <-
function(input,
output,
session,
label = "",
onLabel = "Transaction Store",
offLabel = "Primary Store",
value = F,
on = T,
off = F) {
ns <- session$ns
output[["switch"]] <- renderUI(
shinyWidgets::switchInput(
ns("switch"),
label,
onLabel = onLabel,
offLabel = offLabel,
onStatus = on,
offStatus = off,
value = value
)
)
return(list(selected = reactive(input$switch)))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.