Skip to content

Commit

Permalink
updated updateAwesomeRadio doc
Browse files Browse the repository at this point in the history
  • Loading branch information
pvictor committed Feb 5, 2024
1 parent 3f9539d commit 7881041
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 64 deletions.
55 changes: 6 additions & 49 deletions R/input-awesomeradio.R
Original file line number Diff line number Diff line change
Expand Up @@ -163,62 +163,18 @@ awesomeRadio <- function(inputId,
#' @param inputId The id of the input object.
#' @param label Input label.
#' @param choices List of values to select from (if elements of the list are named then that name rather than the value is displayed to the user)
#' @param selected The initially selected value
#' @param status Color of the buttons
#' @param selected The initially selected value.
#' @param status Color of the buttons, to update status you need to provide `choices`.
#' @param inline If TRUE, render the choices inline (i.e. horizontally)
#' @param checkbox Checkbox style
#'
#' @export
#'
#' @importFrom htmltools tagList
#'
#' @seealso \code{\link{awesomeRadio}}
#' @seealso [awesomeRadio()]
#'
#' @examples
#' if (interactive()) {
#'
#' library("shiny")
#' library("shinyWidgets")
#'
#'
#' ui <- fluidPage(
#' awesomeRadio(
#' inputId = "somevalue",
#' choices = c("A", "B", "C"),
#' label = "My label"
#' ),
#'
#' verbatimTextOutput(outputId = "res"),
#'
#' actionButton(inputId = "updatechoices", label = "Random choices"),
#' textInput(inputId = "updatelabel", label = "Update label")
#' )
#'
#' server <- function(input, output, session) {
#'
#' output$res <- renderPrint({
#' input$somevalue
#' })
#'
#' observeEvent(input$updatechoices, {
#' updateAwesomeRadio(
#' session = session, inputId = "somevalue",
#' choices = sample(letters, sample(2:6))
#' )
#' })
#'
#' observeEvent(input$updatelabel, {
#' updateAwesomeRadio(
#' session = session, inputId = "somevalue",
#' label = input$updatelabel
#' )
#' }, ignoreInit = TRUE)
#'
#' }
#'
#' shinyApp(ui = ui, server = server)
#'
#' }
#' @example examples/updateAwesomeRadio.R
updateAwesomeRadio <- function(session = getDefaultReactiveDomain(),
inputId,
label = NULL,
Expand All @@ -239,7 +195,8 @@ updateAwesomeRadio <- function(session = getDefaultReactiveDomain(),
as.character(generateAwesomeRadio(session$ns(inputId), choices, selected, inline, status, checkbox))
}
message <- dropNulls(list(
label = label, options = options,
label = label,
options = options,
value = selected
))
session$sendInputMessage(inputId, message)
Expand Down
55 changes: 55 additions & 0 deletions examples/updateAwesomeRadio.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
library(shiny)
library(shinyWidgets)


ui <- fluidPage(
awesomeRadio(
inputId = "radio",
choices = c("A", "B", "C"),
label = "My label"
),

verbatimTextOutput(outputId = "res"),

actionButton(inputId = "updatechoices", label = "Random choices"),
textInput(inputId = "updatelabel", label = "Update label"),
selectInput(
inputId = "updatestatus",
label = "Status",
choices = c("primary", "danger", "warning", "success", "info")
)
)

server <- function(input, output, session) {

output$res <- renderPrint({
input$somevalue
})

observeEvent(input$updatechoices, {
updateAwesomeRadio(
inputId = "radio",
choices = sample(letters, sample(2:6, 1))
)
})

observeEvent(input$updatelabel, {
updateAwesomeRadio(
inputId = "radio",
label = input$updatelabel
)
}, ignoreInit = TRUE)

# To update status you need to provide coices too
observeEvent(input$updatestatus, {
updateAwesomeRadio(
inputId = "radio",
choices = c("A", "B", "C"),
status = input$updatestatus
)
}, ignoreInit = TRUE)

}

if (interactive())
shinyApp(ui = ui, server = server)
41 changes: 26 additions & 15 deletions man/updateAwesomeRadio.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7881041

Please sign in to comment.