|
library(shiny) |
|
|
|
myRadioButtons <- function (inputId, label=NULL, choices = NULL, selected = NULL, inline = FALSE, |
|
width = NULL, choiceNames = NULL, choiceValues = NULL) |
|
{ |
|
args <- shiny:::normalizeChoicesArgs(choices, choiceNames, choiceValues) |
|
selected <- shiny:::restoreInput(id = inputId, default = selected) |
|
selected <- if (is.null(selected)) |
|
args$choiceValues[[1]] |
|
else as.character(selected) |
|
if (length(selected) > 1) |
|
stop("The 'selected' argument must be of length 1") |
|
options <- shiny:::generateOptions(inputId, selected, inline, "radio", |
|
args$choiceNames, args$choiceValues) |
|
divClass <- "form-group shiny-input-radiogroup shiny-input-container" |
|
if (inline) |
|
divClass <- paste(divClass, "shiny-input-container-inline") |
|
if (!is.null(label)) { |
|
tags$div(id = inputId, style = if (!is.null(width)) |
|
paste0("width: ", validateCssUnit(width), ";"), class = divClass, |
|
controlLabel(inputId, label), options) |
|
} else { |
|
tags$div(id = inputId, style = if (!is.null(width)) |
|
paste0("width: ", validateCssUnit(width), ";"), class = divClass, |
|
options) |
|
} |
|
} |
|
|
|
ui <- fluidPage( |
|
fluidRow( |
|
column(2, tags$strong('Radio Buttons')), |
|
column(10, |
|
myRadioButtons("radio", |
|
choices = list("Choice 1" = 1, "Choice 2" = 2, "Choice 3" = 3), |
|
selected = 1, inline = TRUE) |
|
|
|
) |
|
) |
|
) |
|
|
|
server <- function(input, output) { |
|
} |
|
|
|
shinyApp(ui, server) |