Skip to content

Instantly share code, notes, and snippets.

@jaehyeon-kim
Created July 3, 2018 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaehyeon-kim/36a9519b483ef2b06eae093b1de7afe0 to your computer and use it in GitHub Desktop.
Save jaehyeon-kim/36a9519b483ef2b06eae093b1de7afe0 to your computer and use it in GitHub Desktop.
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment