#' Radio button module UI
#'
#' @description A radio button module UI that can accept dynamic inputs on the server-side
#' declaration
#' @param id is unique ID associated with the button for the UI namespace
#'
#' @return HTML UI code for a shiny application
#'
#' @importFrom shiny uiOutput
#' @export
radio_buttons_ui <- function(id) {
ns <- NS(id)
uiOutput(ns("radio"))
}
#' Radio button module Server
#'
#' @description A radio button 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{radionButtons} function. Converted to reactive later for enabling encapsulation
#' @param choices The choices of the \code{radionButtons} function.
#' @param inline The option to show the selection inline for the \code{radionButtons} function.
#' @param selected The option selected for the \code{radionButtons} choices.
#'
#' @return Numeric or Character. Radio buttons selected value
#'
#' @importFrom shiny radioButtons
#' @importFrom shiny reactive
#' @export
radio_buttons_server <-
function(input,
output,
session,
label = "Store: ",
choices = c('Transaction' = 'transaction_store', 'Primary' = 'primary_store'),
inline = T,
selected = 'transaction_store') {
ns <- session$ns
label<-to_reactive(label)
choices<-to_reactive(choices)
inline<-to_reactive(inline)
selected<-to_reactive(selected)
output[["radio"]] <-renderUI({
radioButtons(
ns("radio"),
label = label(),
choices = choices(),
inline = inline(),
selected = selected()
)})
return(list(selected = reactive(input$radio)))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.