diff --git a/R/input-pretty.R b/R/input-pretty.R index cfee8cb9..a8d159c2 100644 --- a/R/input-pretty.R +++ b/R/input-pretty.R @@ -23,60 +23,16 @@ #' @importFrom htmltools validateCssUnit tags #' @importFrom shiny restoreInput #' -#' @examples -#' if (interactive()) { -#' -#' library(shiny) -#' library(shinyWidgets) -#' -#' ui <- fluidPage( -#' tags$h1("Pretty switches"), -#' br(), -#' -#' fluidRow( -#' column( -#' width = 4, -#' prettySwitch(inputId = "switch1", label = "Default:"), -#' verbatimTextOutput(outputId = "res1"), -#' br(), -#' prettySwitch(inputId = "switch4", -#' label = "Fill switch with status:", -#' fill = TRUE, status = "primary"), -#' verbatimTextOutput(outputId = "res4") -#' ), -#' column( -#' width = 4, -#' prettySwitch(inputId = "switch2", -#' label = "Danger status:", -#' status = "danger"), -#' verbatimTextOutput(outputId = "res2") -#' ), -#' column( -#' width = 4, -#' prettySwitch(inputId = "switch3", -#' label = "Slim switch:", -#' slim = TRUE), -#' verbatimTextOutput(outputId = "res3") -#' ) -#' ) -#' -#' ) -#' -#' server <- function(input, output, session) { -#' -#' output$res1 <- renderPrint(input$switch1) -#' output$res2 <- renderPrint(input$switch2) -#' output$res3 <- renderPrint(input$switch3) -#' output$res4 <- renderPrint(input$switch4) -#' -#' } -#' -#' shinyApp(ui, server) -#' -#' } -prettySwitch <- function(inputId, label, value = FALSE, status = "default", - slim = FALSE, fill = FALSE, bigger = FALSE, - inline = FALSE, width = NULL) { +#' @example examples/prettySwitch.R +prettySwitch <- function(inputId, + label, + value = FALSE, + status = "default", + slim = FALSE, + fill = FALSE, + bigger = FALSE, + inline = FALSE, + width = NULL) { value <- shiny::restoreInput(id = inputId, default = value) status <- match.arg(status, c("default", "primary", "success", "info", "danger", "warning")) @@ -115,40 +71,11 @@ prettySwitch <- function(inputId, label, value = FALSE, status = "default", #' #' @export #' -#' @examples -#' if (interactive()) { -#' -#' library(shiny) -#' library(shinyWidgets) -#' -#' ui <- fluidPage( -#' tags$h1("Pretty switch update value"), -#' br(), -#' -#' prettySwitch(inputId = "switch1", label = "Update me !"), -#' verbatimTextOutput(outputId = "res1"), -#' radioButtons( -#' inputId = "update", label = "Value to set:", -#' choices = c("FALSE", "TRUE") -#' ) -#' -#' ) -#' -#' server <- function(input, output, session) { -#' -#' output$res1 <- renderPrint(input$switch1) -#' -#' observeEvent(input$update, { -#' updatePrettySwitch(session = session, inputId = "switch1", -#' value = as.logical(input$update)) -#' }) -#' -#' } -#' -#' shinyApp(ui, server) -#' -#' } -updatePrettySwitch<- function (session, inputId, label = NULL, value = NULL) { +#' @example examples/updatePrettySwitch.R +updatePrettySwitch <- function(session, + inputId, + label = NULL, + value = NULL) { message <- dropNulls(list(label = label, value = value)) session$sendInputMessage(inputId, message) } @@ -157,13 +84,6 @@ updatePrettySwitch<- function (session, inputId, label = NULL, value = NULL) { - - - - - - - #' @title Pretty Toggle Input #' #' @description A single checkbox that changes appearance if checked or not. @@ -197,126 +117,24 @@ updatePrettySwitch<- function (session, inputId, label = NULL, value = NULL) { #' @importFrom htmltools validateCssUnit tags #' @importFrom shiny restoreInput #' -#' @examples -#' if (interactive()) { -#' library(shiny) -#' library(shinyWidgets) -#' -#' ui <- fluidPage( -#' tags$h1("Pretty toggles"), -#' br(), -#' -#' fluidRow( -#' column( -#' width = 4, -#' prettyToggle(inputId = "toggle1", -#' label_on = "Checked!", -#' label_off = "Unchecked..."), -#' verbatimTextOutput(outputId = "res1"), -#' br(), -#' prettyToggle(inputId = "toggle4", label_on = "Yes!", -#' label_off = "No..", outline = TRUE, -#' plain = TRUE, -#' icon_on = icon("thumbs-up"), -#' icon_off = icon("thumbs-down")), -#' verbatimTextOutput(outputId = "res4") -#' ), -#' column( -#' width = 4, -#' prettyToggle(inputId = "toggle2", -#' label_on = "Yes!", icon_on = icon("check"), -#' status_on = "info", status_off = "warning", -#' label_off = "No..", icon_off = icon("remove")), -#' verbatimTextOutput(outputId = "res2") -#' ), -#' column( -#' width = 4, -#' prettyToggle(inputId = "toggle3", label_on = "Yes!", -#' label_off = "No..", shape = "round", -#' fill = TRUE, value = TRUE), -#' verbatimTextOutput(outputId = "res3") -#' ) -#' ) -#' -#' ) -#' -#' server <- function(input, output, session) { -#' -#' output$res1 <- renderPrint(input$toggle1) -#' output$res2 <- renderPrint(input$toggle2) -#' output$res3 <- renderPrint(input$toggle3) -#' output$res4 <- renderPrint(input$toggle4) -#' -#' } -#' -#' shinyApp(ui, server) -#' -#' -#' -#' # Inline example ---- -#' -#' -#' ui <- fluidPage( -#' tags$h1("Pretty toggles: inline example"), -#' br(), -#' -#' prettyToggle(inputId = "toggle1", -#' label_on = "Checked!", -#' label_off = "Unchecked...", -#' inline = TRUE), -#' prettyToggle(inputId = "toggle2", -#' label_on = "Yep", -#' status_on = "default", -#' icon_on = icon("ok-circle", lib = "glyphicon"), -#' label_off = "Nope", -#' status_off = "default", -#' icon_off = icon("remove-circle", lib = "glyphicon"), -#' plain = TRUE, -#' inline = TRUE), -#' prettyToggle(inputId = "toggle3", -#' label_on = "", -#' label_off = "", -#' icon_on = icon("volume-up", lib = "glyphicon"), -#' icon_off = icon("volume-off", lib = "glyphicon"), -#' status_on = "primary", -#' status_off = "default", -#' plain = TRUE, -#' outline = TRUE, -#' bigger = TRUE, -#' inline = TRUE), -#' prettyToggle(inputId = "toggle4", -#' label_on = "Yes!", -#' label_off = "No..", -#' outline = TRUE, -#' plain = TRUE, -#' icon_on = icon("thumbs-up"), -#' icon_off = icon("thumbs-down"), -#' inline = TRUE), -#' -#' verbatimTextOutput(outputId = "res") -#' -#' ) -#' -#' server <- function(input, output, session) { -#' -#' output$res <- renderPrint(c(input$toggle1, -#' input$toggle2, -#' input$toggle3, -#' input$toggle4)) -#' -#' } -#' -#' shinyApp(ui, server) -#' -#' } -prettyToggle <- function(inputId, label_on, label_off, icon_on = NULL, +#' @example examples/prettyToggle.R +prettyToggle <- function(inputId, + label_on, + label_off, + icon_on = NULL, icon_off = NULL, - value = FALSE, status_on = "success", + value = FALSE, + status_on = "success", status_off = "danger", shape = c("square", "curve", "round"), - outline = FALSE, fill = FALSE, thick = FALSE, - plain = FALSE, bigger = FALSE, animation = NULL, - inline = FALSE, width = NULL) { + outline = FALSE, + fill = FALSE, + thick = FALSE, + plain = FALSE, + bigger = FALSE, + animation = NULL, + inline = FALSE, + width = NULL) { value <- shiny::restoreInput(id = inputId, default = value) status_on <- match.arg(status_on, c("default", "primary", "success", "info", "danger", "warning")) @@ -379,43 +197,11 @@ prettyToggle <- function(inputId, label_on, label_off, icon_on = NULL, #' #' @export #' -#' @examples -#' if (interactive()) { -#' -#' library(shiny) -#' library(shinyWidgets) -#' -#' ui <- fluidPage( -#' tags$h1("Pretty toggle update value"), -#' br(), -#' -#' prettyToggle(inputId = "toggle1", -#' label_on = "Checked!", -#' label_off = "Unchecked..."), -#' verbatimTextOutput(outputId = "res1"), -#' radioButtons( -#' inputId = "update", label = "Value to set:", -#' choices = c("FALSE", "TRUE") -#' ) -#' -#' ) -#' -#' server <- function(input, output, session) { -#' -#' output$res1 <- renderPrint(input$toggle1) -#' -#' observeEvent(input$update, { -#' updatePrettyToggle(session = session, -#' inputId = "toggle1", -#' value = as.logical(input$update)) -#' }) -#' -#' } -#' -#' shinyApp(ui, server) -#' -#' } -updatePrettyToggle <- function (session, inputId, label = NULL, value = NULL) { +#' @example examples/updatePrettyToggle.R +updatePrettyToggle <- function(session, + inputId, + label = NULL, + value = NULL) { message <- dropNulls(list(label = label, value = value)) session$sendInputMessage(inputId, message) } @@ -460,122 +246,21 @@ updatePrettyToggle <- function (session, inputId, label = NULL, value = NULL) { #' @importFrom htmltools validateCssUnit tags #' @importFrom shiny restoreInput #' -#' @examples -#' if (interactive()) { -#' -#' library(shiny) -#' library(shinyWidgets) -#' -#' ui <- fluidPage( -#' tags$h1("Pretty checkbox"), -#' br(), -#' -#' fluidRow( -#' column( -#' width = 4, -#' prettyCheckbox(inputId = "checkbox1", -#' label = "Click me!"), -#' verbatimTextOutput(outputId = "res1"), -#' br(), -#' prettyCheckbox(inputId = "checkbox4", label = "Click me!", -#' outline = TRUE, -#' plain = TRUE, icon = icon("thumbs-up")), -#' verbatimTextOutput(outputId = "res4") -#' ), -#' column( -#' width = 4, -#' prettyCheckbox(inputId = "checkbox2", -#' label = "Click me!", thick = TRUE, -#' animation = "pulse", status = "info"), -#' verbatimTextOutput(outputId = "res2"), -#' br(), -#' prettyCheckbox(inputId = "checkbox5", -#' label = "Click me!", icon = icon("check"), -#' animation = "tada", status = "default"), -#' verbatimTextOutput(outputId = "res5") -#' ), -#' column( -#' width = 4, -#' prettyCheckbox(inputId = "checkbox3", label = "Click me!", -#' shape = "round", status = "danger", -#' fill = TRUE, value = TRUE), -#' verbatimTextOutput(outputId = "res3") -#' ) -#' ) -#' -#' ) -#' -#' server <- function(input, output, session) { -#' -#' output$res1 <- renderPrint(input$checkbox1) -#' output$res2 <- renderPrint(input$checkbox2) -#' output$res3 <- renderPrint(input$checkbox3) -#' output$res4 <- renderPrint(input$checkbox4) -#' output$res5 <- renderPrint(input$checkbox5) -#' -#' } -#' -#' shinyApp(ui, server) -#' -#' -#' -#' # Inline example ---- -#' -#' ui <- fluidPage( -#' tags$h1("Pretty checkbox: inline example"), -#' br(), -#' prettyCheckbox(inputId = "checkbox1", -#' label = "Click me!", -#' status = "success", -#' outline = TRUE, -#' inline = TRUE), -#' prettyCheckbox(inputId = "checkbox2", -#' label = "Click me!", -#' thick = TRUE, -#' shape = "curve", -#' animation = "pulse", -#' status = "info", -#' inline = TRUE), -#' prettyCheckbox(inputId = "checkbox3", -#' label = "Click me!", -#' shape = "round", -#' status = "danger", -#' value = TRUE, -#' inline = TRUE), -#' prettyCheckbox(inputId = "checkbox4", -#' label = "Click me!", -#' outline = TRUE, -#' plain = TRUE, -#' animation = "rotate", -#' icon = icon("thumbs-up"), -#' inline = TRUE), -#' prettyCheckbox(inputId = "checkbox5", -#' label = "Click me!", -#' icon = icon("check"), -#' animation = "tada", -#' status = "primary", -#' inline = TRUE), -#' verbatimTextOutput(outputId = "res") -#' ) -#' -#' server <- function(input, output, session) { -#' -#' output$res <- renderPrint(c(input$checkbox1, -#' input$checkbox2, -#' input$checkbox3, -#' input$checkbox4, -#' input$checkbox5)) -#' -#' } -#' -#' shinyApp(ui, server) -#' -#' } -prettyCheckbox <- function(inputId, label, value = FALSE, status = "default", +#' @example examples/prettyCheckbox.R +prettyCheckbox <- function(inputId, + label, + value = FALSE, + status = "default", shape = c("square", "curve", "round"), - outline = FALSE, fill = FALSE, thick = FALSE, - animation = NULL, icon = NULL, plain = FALSE, - bigger = FALSE, inline = FALSE, width = NULL) { + outline = FALSE, + fill = FALSE, + thick = FALSE, + animation = NULL, + icon = NULL, + plain = FALSE, + bigger = FALSE, + inline = FALSE, + width = NULL) { value <- shiny::restoreInput(id = inputId, default = value) status <- match.arg(status, c("default", "primary", "success", "info", "danger", "warning")) @@ -626,43 +311,11 @@ prettyCheckbox <- function(inputId, label, value = FALSE, status = "default", #' #' @export #' -#' @examples -#' if (interactive()) { -#' -#' library(shiny) -#' library(shinyWidgets) -#' -#' ui <- fluidPage( -#' tags$h1("Pretty checkbox update value"), -#' br(), -#' -#' prettyCheckbox(inputId = "checkbox1", -#' label = "Update me!", -#' shape = "curve", thick = TRUE, outline = TRUE), -#' verbatimTextOutput(outputId = "res1"), -#' radioButtons( -#' inputId = "update", label = "Value to set:", -#' choices = c("FALSE", "TRUE") -#' ) -#' -#' ) -#' -#' server <- function(input, output, session) { -#' -#' output$res1 <- renderPrint(input$checkbox1) -#' -#' observeEvent(input$update, { -#' updatePrettyToggle(session = session, -#' inputId = "checkbox1", -#' value = as.logical(input$update)) -#' }) -#' -#' } -#' -#' shinyApp(ui, server) -#' -#' } -updatePrettyCheckbox<- function (session, inputId, label = NULL, value = NULL) { +#' @example examples/updatePrettyCheckbox.R +updatePrettyCheckbox <- function(session, + inputId, + label = NULL, + value = NULL) { message <- dropNulls(list(label = label, value = value)) session$sendInputMessage(inputId, message) } @@ -673,10 +326,6 @@ updatePrettyCheckbox<- function (session, inputId, label = NULL, value = NULL) { - - - - #' @title Pretty Checkbox Group Input Control #' #' @description Create a group of pretty checkboxes that can be @@ -716,76 +365,23 @@ updatePrettyCheckbox<- function (session, inputId, label = NULL, value = NULL) { #' @importFrom htmltools validateCssUnit tags tagList #' @importFrom shiny restoreInput #' -#' @examples -#' if (interactive()) { -#' -#' library(shiny) -#' library(shinyWidgets) -#' -#' ui <- fluidPage( -#' tags$h1("Pretty checkbox group"), -#' br(), -#' -#' fluidRow( -#' column( -#' width = 4, -#' prettyCheckboxGroup(inputId = "checkgroup1", -#' label = "Click me!", -#' choices = c("Click me !", "Me !", "Or me !")), -#' verbatimTextOutput(outputId = "res1"), -#' br(), -#' prettyCheckboxGroup(inputId = "checkgroup4", label = "Click me!", -#' choices = c("Click me !", "Me !", "Or me !"), -#' outline = TRUE, -#' plain = TRUE, icon = icon("thumbs-up")), -#' verbatimTextOutput(outputId = "res4") -#' ), -#' column( -#' width = 4, -#' prettyCheckboxGroup(inputId = "checkgroup2", -#' label = "Click me!", thick = TRUE, -#' choices = c("Click me !", "Me !", "Or me !"), -#' animation = "pulse", status = "info"), -#' verbatimTextOutput(outputId = "res2"), -#' br(), -#' prettyCheckboxGroup(inputId = "checkgroup5", -#' label = "Click me!", icon = icon("check"), -#' choices = c("Click me !", "Me !", "Or me !"), -#' animation = "tada", status = "default"), -#' verbatimTextOutput(outputId = "res5") -#' ), -#' column( -#' width = 4, -#' prettyCheckboxGroup(inputId = "checkgroup3", label = "Click me!", -#' choices = c("Click me !", "Me !", "Or me !"), -#' shape = "round", status = "danger", -#' fill = TRUE, inline = TRUE), -#' verbatimTextOutput(outputId = "res3") -#' ) -#' ) -#' -#' ) -#' -#' server <- function(input, output, session) { -#' -#' output$res1 <- renderPrint(input$checkgroup1) -#' output$res2 <- renderPrint(input$checkgroup2) -#' output$res3 <- renderPrint(input$checkgroup3) -#' output$res4 <- renderPrint(input$checkgroup4) -#' output$res5 <- renderPrint(input$checkgroup5) -#' -#' } -#' -#' shinyApp(ui, server) -#' -#' } -prettyCheckboxGroup <- function(inputId, label, choices = NULL, - selected = NULL, status = "default", +#' @example examples/prettyCheckboxGroup.R +prettyCheckboxGroup <- function(inputId, + label, + choices = NULL, + selected = NULL, + status = "default", shape = c("square", "curve", "round"), - outline = FALSE, fill = FALSE, thick = FALSE, - animation = NULL, icon = NULL, - plain = FALSE, bigger = FALSE, inline = FALSE, - width = NULL, choiceNames = NULL, + outline = FALSE, + fill = FALSE, + thick = FALSE, + animation = NULL, + icon = NULL, + plain = FALSE, + bigger = FALSE, + inline = FALSE, + width = NULL, + choiceNames = NULL, choiceValues = NULL) { status <- match.arg(status, c("default", "primary", "success", "info", "danger", "warning")) @@ -900,79 +496,21 @@ generatePretty <- function(inputId, selected, inline, type = "checkbox", #' @param inline If \code{TRUE}, render the choices inline (i.e. horizontally). #' @param choiceNames The choices names to set for the input object. #' @param choiceValues The choices values to set for the input object. -#' @param prettyOptions Arguments passed to \code{\link{prettyCheckboxGroup}} for styling checkboxes. +#' @param prettyOptions Arguments passed to \code{\link{prettyCheckboxGroup}} +#' for styling checkboxes. This can be needed if you update choices. #' #' @export #' -#' @examples -#' if (interactive()) { -#' -#' library(shiny) -#' library(shinyWidgets) -#' -#' ui <- fluidPage( -#' tags$h1("Update pretty checkbox group"), -#' br(), -#' -#' fluidRow( -#' column( -#' width = 6, -#' prettyCheckboxGroup(inputId = "checkgroup1", -#' label = "Update my value!", -#' choices = month.name[1:4], -#' status = "danger", -#' icon = icon("remove")), -#' verbatimTextOutput(outputId = "res1"), -#' br(), -#' checkboxGroupInput( -#' inputId = "update1", label = "Update value :", -#' choices = month.name[1:4], inline = TRUE -#' ) -#' ), -#' column( -#' width = 6, -#' prettyCheckboxGroup(inputId = "checkgroup2", -#' label = "Update my choices!", thick = TRUE, -#' choices = month.name[1:4], -#' animation = "pulse", status = "info"), -#' verbatimTextOutput(outputId = "res2"), -#' br(), -#' actionButton(inputId = "update2", label = "Update choices !") -#' ) -#' ) -#' -#' ) -#' -#' server <- function(input, output, session) { -#' -#' output$res1 <- renderPrint(input$checkgroup1) -#' -#' observeEvent(input$update1, { -#' if (is.null(input$update1)) { -#' selected_ <- character(0) # no choice selected -#' } else { -#' selected_ <- input$update1 -#' } -#' updatePrettyCheckboxGroup(session = session, inputId = "checkgroup1", selected = selected_) -#' }, ignoreNULL = FALSE) -#' -#' output$res2 <- renderPrint(input$checkgroup2) -#' observeEvent(input$update2, { -#' updatePrettyCheckboxGroup( -#' session = session, inputId = "checkgroup2", -#' choices = sample(month.name, 4), prettyOptions = list(animation = "pulse", status = "info") -#' ) -#' }, ignoreInit = TRUE) -#' -#' } -#' -#' shinyApp(ui, server) -#' -#' } -updatePrettyCheckboxGroup <- function (session, inputId, label = NULL, - choices = NULL, selected = NULL, - inline = FALSE, choiceNames = NULL, choiceValues = NULL, - prettyOptions = list()) { +#' @example examples/updatePrettyCheckboxGroup.R +updatePrettyCheckboxGroup <- function(session, + inputId, + label = NULL, + choices = NULL, + selected = NULL, + inline = FALSE, + choiceNames = NULL, + choiceValues = NULL, + prettyOptions = list()) { updatePrettyOptions( session, inputId, label, choices, selected, inline, "checkbox", choiceNames, choiceValues, prettyOptions @@ -981,10 +519,16 @@ updatePrettyCheckboxGroup <- function (session, inputId, label = NULL, -updatePrettyOptions <- function (session, inputId, label = NULL, - choices = NULL, selected = NULL, - inline = FALSE, type = NULL, choiceNames = NULL, - choiceValues = NULL, prettyOptions = list()) { +updatePrettyOptions <- function(session, + inputId, + label = NULL, + choices = NULL, + selected = NULL, + inline = FALSE, + type = NULL, + choiceNames = NULL, + choiceValues = NULL, + prettyOptions = list()) { if (is.null(type)) stop("Please specify the type ('checkbox' or 'radio')") args <- normalizeChoicesArgs(choices, choiceNames, choiceValues, @@ -993,17 +537,23 @@ updatePrettyOptions <- function (session, inputId, label = NULL, selected <- as.character(selected) options <- if (!is.null(args$choiceValues)) { htmltools::doRenderTags( - generatePretty(inputId = session$ns(inputId), selected = selected, inline = inline, type = type, - choiceNames = args$choiceNames, choiceValues = args$choiceValues, - status = prettyOptions$status %||% "primary", - shape = prettyOptions$shape %||% "square", - outline = prettyOptions$outline %||% FALSE, - fill = prettyOptions$fill %||% FALSE, - thick = prettyOptions$thick %||% FALSE, - animation = prettyOptions$animation, - icon = prettyOptions$icon, - plain = prettyOptions$plain %||% FALSE, - bigger = prettyOptions$bigger %||% FALSE) + generatePretty( + inputId = session$ns(inputId), + selected = selected, + inline = inline, + type = type, + choiceNames = args$choiceNames, + choiceValues = args$choiceValues, + status = prettyOptions$status %||% "default", + shape = prettyOptions$shape %||% "square", + outline = prettyOptions$outline %||% FALSE, + fill = prettyOptions$fill %||% FALSE, + thick = prettyOptions$thick %||% FALSE, + animation = prettyOptions$animation, + icon = prettyOptions$icon, + plain = prettyOptions$plain %||% FALSE, + bigger = prettyOptions$bigger %||% FALSE + ) ) } message <- dropNulls(list(label = label, options = options, @@ -1015,13 +565,6 @@ updatePrettyOptions <- function (session, inputId, label = NULL, - - - - - - - #' @title Pretty radio Buttons Input Control #' #' @description Create a set of radio buttons used to select an item from a list. @@ -1057,76 +600,23 @@ updatePrettyOptions <- function (session, inputId, label = NULL, #' @importFrom htmltools validateCssUnit tags tagList #' @importFrom shiny restoreInput #' -#' @examples -#' if (interactive()) { -#' -#' library(shiny) -#' library(shinyWidgets) -#' -#' ui <- fluidPage( -#' tags$h1("Pretty radio buttons"), -#' br(), -#' -#' fluidRow( -#' column( -#' width = 4, -#' prettyRadioButtons(inputId = "radio1", -#' label = "Click me!", -#' choices = c("Click me !", "Me !", "Or me !")), -#' verbatimTextOutput(outputId = "res1"), -#' br(), -#' prettyRadioButtons(inputId = "radio4", label = "Click me!", -#' choices = c("Click me !", "Me !", "Or me !"), -#' outline = TRUE, -#' plain = TRUE, icon = icon("thumbs-up")), -#' verbatimTextOutput(outputId = "res4") -#' ), -#' column( -#' width = 4, -#' prettyRadioButtons(inputId = "radio2", -#' label = "Click me!", thick = TRUE, -#' choices = c("Click me !", "Me !", "Or me !"), -#' animation = "pulse", status = "info"), -#' verbatimTextOutput(outputId = "res2"), -#' br(), -#' prettyRadioButtons(inputId = "radio5", -#' label = "Click me!", icon = icon("check"), -#' choices = c("Click me !", "Me !", "Or me !"), -#' animation = "tada", status = "default"), -#' verbatimTextOutput(outputId = "res5") -#' ), -#' column( -#' width = 4, -#' prettyRadioButtons(inputId = "radio3", label = "Click me!", -#' choices = c("Click me !", "Me !", "Or me !"), -#' shape = "round", status = "danger", -#' fill = TRUE, inline = TRUE), -#' verbatimTextOutput(outputId = "res3") -#' ) -#' ) -#' -#' ) -#' -#' server <- function(input, output, session) { -#' -#' output$res1 <- renderPrint(input$radio1) -#' output$res2 <- renderPrint(input$radio2) -#' output$res3 <- renderPrint(input$radio3) -#' output$res4 <- renderPrint(input$radio4) -#' output$res5 <- renderPrint(input$radio5) -#' -#' } -#' -#' shinyApp(ui, server) -#' -#' } -prettyRadioButtons <- function(inputId, label, choices = NULL, - selected = NULL, status = "primary", +#' @example examples/prettyRadioButtons.R +prettyRadioButtons <- function(inputId, + label, + choices = NULL, + selected = NULL, + status = "primary", shape = c("round", "square", "curve"), - outline = FALSE, fill = FALSE, thick = FALSE, - animation = NULL, icon = NULL, plain = FALSE, - bigger = FALSE, inline = FALSE, - width = NULL, choiceNames = NULL, + outline = FALSE, + fill = FALSE, + thick = FALSE, + animation = NULL, + icon = NULL, + plain = FALSE, + bigger = FALSE, + inline = FALSE, + width = NULL, + choiceNames = NULL, choiceValues = NULL) { status <- match.arg(status, c("default", "primary", "success", "info", "danger", "warning")) @@ -1178,85 +668,31 @@ prettyRadioButtons <- function(inputId, label, choices = NULL, #' @param inline If \code{TRUE}, render the choices inline (i.e. horizontally). #' @param choiceNames The choices names to set for the input object. #' @param choiceValues The choices values to set for the input object. -#' @param prettyOptions Arguments passed to \code{\link{prettyRadioButtons}} for styling radio buttons +#' @param prettyOptions Arguments passed to \code{\link{prettyRadioButtons}} +#' for styling radio buttons. This can be needed if you update choices. #' #' @export #' -#' @examples -#' if (interactive()) { -#' -#' library(shiny) -#' library(shinyWidgets) -#' -#' ui <- fluidPage( -#' tags$h1("Update pretty radio buttons"), -#' br(), -#' -#' fluidRow( -#' column( -#' width = 6, -#' prettyRadioButtons(inputId = "radio1", -#' label = "Update my value!", -#' choices = month.name[1:4], -#' status = "danger", -#' icon = icon("remove")), -#' verbatimTextOutput(outputId = "res1"), -#' br(), -#' radioButtons( -#' inputId = "update1", label = "Update value :", -#' choices = month.name[1:4], inline = TRUE -#' ) -#' ), -#' column( -#' width = 6, -#' prettyRadioButtons(inputId = "radio2", -#' label = "Update my choices!", thick = TRUE, -#' choices = month.name[1:4], -#' animation = "pulse", status = "info"), -#' verbatimTextOutput(outputId = "res2"), -#' br(), -#' actionButton(inputId = "update2", label = "Update choices !") -#' ) -#' ) -#' -#' ) -#' -#' server <- function(input, output, session) { -#' -#' output$res1 <- renderPrint(input$radio1) -#' -#' observeEvent(input$update1, { -#' updatePrettyRadioButtons( -#' session = session, -#' inputId = "radio1", -#' selected = input$update1 -#' ) -#' }, ignoreNULL = FALSE) -#' -#' output$res2 <- renderPrint(input$radio2) -#' observeEvent(input$update2, { -#' updatePrettyRadioButtons( -#' session = session, inputId = "radio2", -#' choices = sample(month.name, 4), -#' prettyOptions = list(animation = "pulse", -#' status = "info", -#' shape = "round") -#' ) -#' }, ignoreInit = TRUE) -#' -#' } -#' -#' shinyApp(ui, server) -#' -#' } -updatePrettyRadioButtons <- function (session, inputId, label = NULL, choices = NULL, selected = NULL, - inline = FALSE, choiceNames = NULL, choiceValues = NULL, prettyOptions = list()) { +#' @example examples/updatePrettyRadioButtons.R +updatePrettyRadioButtons <- function(session, + inputId, + label = NULL, + choices = NULL, + selected = NULL, + inline = FALSE, + choiceNames = NULL, + choiceValues = NULL, + prettyOptions = list()) { if (is.null(selected)) { if (!is.null(choices)) selected <- choices[[1]] else if (!is.null(choiceValues)) selected <- choiceValues[[1]] } + if (is.list(prettyOptions) && is.null(prettyOptions$shape)) + prettyOptions$shape <- "round" + if (is.list(prettyOptions) && is.null(prettyOptions$status)) + prettyOptions$status <- "primary" updatePrettyOptions( session, inputId, label, choices, selected, inline, "radio", choiceNames, choiceValues, prettyOptions diff --git a/examples/prettyCheckbox.R b/examples/prettyCheckbox.R new file mode 100644 index 00000000..3774ed1e --- /dev/null +++ b/examples/prettyCheckbox.R @@ -0,0 +1,141 @@ +library(shiny) +library(shinyWidgets) + +ui <- fluidPage( + tags$h1("Pretty checkbox"), + br(), + + fluidRow( + column( + width = 4, + prettyCheckbox( + inputId = "checkbox1", + label = "Click me!" + ), + verbatimTextOutput(outputId = "res1"), + br(), + prettyCheckbox( + inputId = "checkbox4", + label = "Click me!", + outline = TRUE, + plain = TRUE, + icon = icon("thumbs-up") + ), + verbatimTextOutput(outputId = "res4") + ), + column( + width = 4, + prettyCheckbox( + inputId = "checkbox2", + label = "Click me!", + thick = TRUE, + animation = "pulse", + status = "info" + ), + verbatimTextOutput(outputId = "res2"), + br(), + prettyCheckbox( + inputId = "checkbox5", + label = "Click me!", + icon = icon("check"), + animation = "tada", + status = "default" + ), + verbatimTextOutput(outputId = "res5") + ), + column( + width = 4, + prettyCheckbox( + inputId = "checkbox3", + label = "Click me!", + shape = "round", + status = "danger", + fill = TRUE, + value = TRUE + ), + verbatimTextOutput(outputId = "res3") + ) + ) + +) + +server <- function(input, output, session) { + + output$res1 <- renderPrint(input$checkbox1) + output$res2 <- renderPrint(input$checkbox2) + output$res3 <- renderPrint(input$checkbox3) + output$res4 <- renderPrint(input$checkbox4) + output$res5 <- renderPrint(input$checkbox5) + +} + +if (interactive()) + shinyApp(ui, server) + + + + +# Inline example ---- + +ui <- fluidPage( + tags$h1("Pretty checkbox: inline example"), + br(), + prettyCheckbox( + inputId = "checkbox1", + label = "Click me!", + status = "success", + outline = TRUE, + inline = TRUE + ), + prettyCheckbox( + inputId = "checkbox2", + label = "Click me!", + thick = TRUE, + shape = "curve", + animation = "pulse", + status = "info", + inline = TRUE + ), + prettyCheckbox( + inputId = "checkbox3", + label = "Click me!", + shape = "round", + status = "danger", + value = TRUE, + inline = TRUE + ), + prettyCheckbox( + inputId = "checkbox4", + label = "Click me!", + outline = TRUE, + plain = TRUE, + animation = "rotate", + icon = icon("thumbs-up"), + inline = TRUE + ), + prettyCheckbox( + inputId = "checkbox5", + label = "Click me!", + icon = icon("check"), + animation = "tada", + status = "primary", + inline = TRUE + ), + verbatimTextOutput(outputId = "res") +) + +server <- function(input, output, session) { + + output$res <- renderPrint( + c(input$checkbox1, + input$checkbox2, + input$checkbox3, + input$checkbox4, + input$checkbox5) + ) + +} + +if (interactive()) + shinyApp(ui, server) + diff --git a/examples/prettyCheckboxGroup.R b/examples/prettyCheckboxGroup.R new file mode 100644 index 00000000..77f4ab7f --- /dev/null +++ b/examples/prettyCheckboxGroup.R @@ -0,0 +1,79 @@ +library(shiny) +library(shinyWidgets) + +ui <- fluidPage( + tags$h1("Pretty checkbox group"), + br(), + + fluidRow( + column( + width = 4, + prettyCheckboxGroup( + inputId = "checkgroup1", + label = "Click me!", + choices = c("Click me !", "Me !", "Or me !") + ), + verbatimTextOutput(outputId = "res1"), + br(), + prettyCheckboxGroup( + inputId = "checkgroup4", + label = "Click me!", + choices = c("Click me !", "Me !", "Or me !"), + outline = TRUE, + plain = TRUE, + icon = icon("thumbs-up") + ), + verbatimTextOutput(outputId = "res4") + ), + column( + width = 4, + prettyCheckboxGroup( + inputId = "checkgroup2", + label = "Click me!", + thick = TRUE, + choices = c("Click me !", "Me !", "Or me !"), + animation = "pulse", + status = "info" + ), + verbatimTextOutput(outputId = "res2"), + br(), + prettyCheckboxGroup( + inputId = "checkgroup5", + label = "Click me!", + icon = icon("check"), + choices = c("Click me !", "Me !", "Or me !"), + animation = "tada", + status = "default" + ), + verbatimTextOutput(outputId = "res5") + ), + column( + width = 4, + prettyCheckboxGroup( + inputId = "checkgroup3", + label = "Click me!", + choices = c("Click me !", "Me !", "Or me !"), + shape = "round", + status = "danger", + fill = TRUE, + inline = TRUE + ), + verbatimTextOutput(outputId = "res3") + ) + ) + +) + +server <- function(input, output, session) { + + output$res1 <- renderPrint(input$checkgroup1) + output$res2 <- renderPrint(input$checkgroup2) + output$res3 <- renderPrint(input$checkgroup3) + output$res4 <- renderPrint(input$checkgroup4) + output$res5 <- renderPrint(input$checkgroup5) + +} + +if (interactive()) + shinyApp(ui, server) + diff --git a/examples/prettyRadioButtons.R b/examples/prettyRadioButtons.R new file mode 100644 index 00000000..09101351 --- /dev/null +++ b/examples/prettyRadioButtons.R @@ -0,0 +1,78 @@ +library(shiny) +library(shinyWidgets) + +ui <- fluidPage( + tags$h1("Pretty radio buttons"), + br(), + + fluidRow( + column( + width = 4, + prettyRadioButtons( + inputId = "radio1", + label = "Click me!", + choices = c("Click me !", "Me !", "Or me !") + ), + verbatimTextOutput(outputId = "res1"), + br(), + prettyRadioButtons( + inputId = "radio4", + label = "Click me!", + choices = c("Click me !", "Me !", "Or me !"), + outline = TRUE, + plain = TRUE, + icon = icon("thumbs-up") + ), + verbatimTextOutput(outputId = "res4") + ), + column( + width = 4, + prettyRadioButtons( + inputId = "radio2", + label = "Click me!", + thick = TRUE, + choices = c("Click me !", "Me !", "Or me !"), + animation = "pulse", + status = "info" + ), + verbatimTextOutput(outputId = "res2"), + br(), + prettyRadioButtons( + inputId = "radio5", + label = "Click me!", + icon = icon("check"), + choices = c("Click me !", "Me !", "Or me !"), + animation = "tada", + status = "default" + ), + verbatimTextOutput(outputId = "res5") + ), + column( + width = 4, + prettyRadioButtons( + inputId = "radio3", + label = "Click me!", + choices = c("Click me !", "Me !", "Or me !"), + shape = "round", + status = "danger", + fill = TRUE, + inline = TRUE + ), + verbatimTextOutput(outputId = "res3") + ) + ) + +) + +server <- function(input, output, session) { + + output$res1 <- renderPrint(input$radio1) + output$res2 <- renderPrint(input$radio2) + output$res3 <- renderPrint(input$radio3) + output$res4 <- renderPrint(input$radio4) + output$res5 <- renderPrint(input$radio5) + +} + +if (interactive()) + shinyApp(ui, server) diff --git a/examples/prettySwitch.R b/examples/prettySwitch.R new file mode 100644 index 00000000..774200c0 --- /dev/null +++ b/examples/prettySwitch.R @@ -0,0 +1,53 @@ +library(shiny) +library(shinyWidgets) + +ui <- fluidPage( + tags$h1("Pretty switches"), + br(), + + fluidRow( + column( + width = 4, + prettySwitch(inputId = "switch1", label = "Default:"), + verbatimTextOutput(outputId = "res1"), + br(), + prettySwitch( + inputId = "switch4", + label = "Fill switch with status:", + fill = TRUE, status = "primary" + ), + verbatimTextOutput(outputId = "res4") + ), + column( + width = 4, + prettySwitch( + inputId = "switch2", + label = "Danger status:", + status = "danger" + ), + verbatimTextOutput(outputId = "res2") + ), + column( + width = 4, + prettySwitch( + inputId = "switch3", + label = "Slim switch:", + slim = TRUE + ), + verbatimTextOutput(outputId = "res3") + ) + ) + +) + +server <- function(input, output, session) { + + output$res1 <- renderPrint(input$switch1) + output$res2 <- renderPrint(input$switch2) + output$res3 <- renderPrint(input$switch3) + output$res4 <- renderPrint(input$switch4) + +} + +if (interactive()) + shinyApp(ui, server) diff --git a/examples/prettyToggle.R b/examples/prettyToggle.R new file mode 100644 index 00000000..32a012bd --- /dev/null +++ b/examples/prettyToggle.R @@ -0,0 +1,128 @@ +library(shiny) +library(shinyWidgets) + +ui <- fluidPage( + tags$h1("Pretty toggles"), + br(), + + fluidRow( + column( + width = 4, + prettyToggle( + inputId = "toggle1", + label_on = "Checked!", + label_off = "Unchecked..." + ), + verbatimTextOutput(outputId = "res1"), + br(), + prettyToggle( + inputId = "toggle4", label_on = "Yes!", + label_off = "No..", outline = TRUE, + plain = TRUE, + icon_on = icon("thumbs-up"), + icon_off = icon("thumbs-down") + ), + verbatimTextOutput(outputId = "res4") + ), + column( + width = 4, + prettyToggle( + inputId = "toggle2", + label_on = "Yes!", icon_on = icon("check"), + status_on = "info", status_off = "warning", + label_off = "No..", icon_off = icon("remove") + ), + verbatimTextOutput(outputId = "res2") + ), + column( + width = 4, + prettyToggle( + inputId = "toggle3", label_on = "Yes!", + label_off = "No..", shape = "round", + fill = TRUE, value = TRUE + ), + verbatimTextOutput(outputId = "res3") + ) + ) + +) + +server <- function(input, output, session) { + + output$res1 <- renderPrint(input$toggle1) + output$res2 <- renderPrint(input$toggle2) + output$res3 <- renderPrint(input$toggle3) + output$res4 <- renderPrint(input$toggle4) + +} + +if (interactive()) + shinyApp(ui, server) + + + + +# Inline example ---- + +ui <- fluidPage( + tags$h1("Pretty toggles: inline example"), + br(), + + prettyToggle( + inputId = "toggle1", + label_on = "Checked!", + label_off = "Unchecked...", + inline = TRUE + ), + prettyToggle( + inputId = "toggle2", + label_on = "Yep", + status_on = "default", + icon_on = icon("ok-circle", lib = "glyphicon"), + label_off = "Nope", + status_off = "default", + icon_off = icon("remove-circle", lib = "glyphicon"), + plain = TRUE, + inline = TRUE + ), + prettyToggle( + inputId = "toggle3", + label_on = "", + label_off = "", + icon_on = icon("volume-up", lib = "glyphicon"), + icon_off = icon("volume-off", lib = "glyphicon"), + status_on = "primary", + status_off = "default", + plain = TRUE, + outline = TRUE, + bigger = TRUE, + inline = TRUE + ), + prettyToggle( + inputId = "toggle4", + label_on = "Yes!", + label_off = "No..", + outline = TRUE, + plain = TRUE, + icon_on = icon("thumbs-up"), + icon_off = icon("thumbs-down"), + inline = TRUE + ), + + verbatimTextOutput(outputId = "res") + +) + +server <- function(input, output, session) { + + output$res <- renderPrint( + c(input$toggle1, + input$toggle2, + input$toggle3, + input$toggle4) + ) + +} + +if (interactive()) + shinyApp(ui, server) diff --git a/examples/updatePrettyCheckbox.R b/examples/updatePrettyCheckbox.R new file mode 100644 index 00000000..9ea73a4c --- /dev/null +++ b/examples/updatePrettyCheckbox.R @@ -0,0 +1,39 @@ +library(shiny) +library(shinyWidgets) + +ui <- fluidPage( + tags$h1("Pretty checkbox update value"), + br(), + + prettyCheckbox( + inputId = "checkbox1", + label = "Update me!", + shape = "curve", + thick = TRUE, + outline = TRUE + ), + verbatimTextOutput(outputId = "res1"), + radioButtons( + inputId = "update", + label = "Value to set:", + choices = c("FALSE", "TRUE") + ) + +) + +server <- function(input, output, session) { + + output$res1 <- renderPrint(input$checkbox1) + + observeEvent(input$update, { + updatePrettyCheckbox( + session = session, + inputId = "checkbox1", + value = as.logical(input$update) + ) + }) + +} + +if (interactive()) + shinyApp(ui, server) diff --git a/examples/updatePrettyCheckboxGroup.R b/examples/updatePrettyCheckboxGroup.R new file mode 100644 index 00000000..78b3b877 --- /dev/null +++ b/examples/updatePrettyCheckboxGroup.R @@ -0,0 +1,74 @@ +library(shiny) +library(shinyWidgets) + +ui <- fluidPage( + tags$h1("Update pretty checkbox group"), + br(), + + fluidRow( + column( + width = 6, + prettyCheckboxGroup( + inputId = "checkgroup1", + label = "Update my value!", + choices = month.name[1:4], + status = "danger", + icon = icon("remove") + ), + verbatimTextOutput(outputId = "res1"), + br(), + checkboxGroupInput( + inputId = "update1", label = "Update value :", + choices = month.name[1:4], inline = TRUE + ) + ), + column( + width = 6, + prettyCheckboxGroup( + inputId = "checkgroup2", + label = "Update my choices!", + thick = TRUE, + choices = month.name[1:4], + animation = "pulse", + status = "info" + ), + verbatimTextOutput(outputId = "res2"), + br(), + actionButton(inputId = "update2", label = "Update choices !") + ) + ) + +) + +server <- function(input, output, session) { + + output$res1 <- renderPrint(input$checkgroup1) + + observeEvent(input$update1, { + if (is.null(input$update1)) { + selected_ <- character(0) # no choice selected + } else { + selected_ <- input$update1 + } + updatePrettyCheckboxGroup( + session = session, + inputId = "checkgroup1", + selected = selected_ + ) + }, ignoreNULL = FALSE) + + output$res2 <- renderPrint(input$checkgroup2) + observeEvent(input$update2, { + updatePrettyCheckboxGroup( + session = session, + inputId = "checkgroup2", + choices = sample(month.name, 4), + prettyOptions = list(animation = "pulse", status = "info") + ) + }, ignoreInit = TRUE) + +} + +if (interactive()) + shinyApp(ui, server) + diff --git a/examples/updatePrettyRadioButtons.R b/examples/updatePrettyRadioButtons.R new file mode 100644 index 00000000..fb36539f --- /dev/null +++ b/examples/updatePrettyRadioButtons.R @@ -0,0 +1,70 @@ +library(shiny) +library(shinyWidgets) + +ui <- fluidPage( + tags$h1("Update pretty radio buttons"), + br(), + + fluidRow( + column( + width = 6, + prettyRadioButtons( + inputId = "radio1", + label = "Update my value!", + choices = month.name[1:4], + status = "danger", + icon = icon("remove") + ), + verbatimTextOutput(outputId = "res1"), + br(), + radioButtons( + inputId = "update1", label = "Update value :", + choices = month.name[1:4], inline = TRUE + ) + ), + column( + width = 6, + prettyRadioButtons( + inputId = "radio2", + label = "Update my choices!", + thick = TRUE, + choices = month.name[1:4], + animation = "pulse", + status = "info" + ), + verbatimTextOutput(outputId = "res2"), + br(), + actionButton(inputId = "update2", label = "Update choices !") + ) + ) + +) + +server <- function(input, output, session) { + + output$res1 <- renderPrint(input$radio1) + + observeEvent(input$update1, { + updatePrettyRadioButtons( + session = session, + inputId = "radio1", + selected = input$update1 + ) + }, ignoreNULL = FALSE) + + output$res2 <- renderPrint(input$radio2) + observeEvent(input$update2, { + updatePrettyRadioButtons( + session = session, + inputId = "radio2", + choices = sample(month.name, 4), + prettyOptions = list(animation = "pulse", + status = "info", + shape = "round") + ) + }, ignoreInit = TRUE) + +} + +if (interactive()) + shinyApp(ui, server) diff --git a/examples/updatePrettySwitch.R b/examples/updatePrettySwitch.R new file mode 100644 index 00000000..deb55152 --- /dev/null +++ b/examples/updatePrettySwitch.R @@ -0,0 +1,33 @@ +library(shiny) +library(shinyWidgets) + +ui <- fluidPage( + tags$h1("Pretty switch update value"), + br(), + + prettySwitch(inputId = "switch1", label = "Update me !"), + verbatimTextOutput(outputId = "res1"), + radioButtons( + inputId = "update", + label = "Value to set:", + choices = c("FALSE", "TRUE") + ) + +) + +server <- function(input, output, session) { + + output$res1 <- renderPrint(input$switch1) + + observeEvent(input$update, { + updatePrettySwitch( + session = session, + inputId = "switch1", + value = as.logical(input$update) + ) + }) + +} + +if (interactive()) + shinyApp(ui, server) diff --git a/examples/updatePrettyToggle.R b/examples/updatePrettyToggle.R new file mode 100644 index 00000000..f6b142c5 --- /dev/null +++ b/examples/updatePrettyToggle.R @@ -0,0 +1,37 @@ +library(shiny) +library(shinyWidgets) + +ui <- fluidPage( + tags$h1("Pretty toggle update value"), + br(), + + prettyToggle( + inputId = "toggle1", + label_on = "Checked!", + label_off = "Unchecked..." + ), + verbatimTextOutput(outputId = "res1"), + radioButtons( + inputId = "update", + label = "Value to set:", + choices = c("FALSE", "TRUE") + ) + +) + +server <- function(input, output, session) { + + output$res1 <- renderPrint(input$toggle1) + + observeEvent(input$update, { + updatePrettyToggle( + session = session, + inputId = "toggle1", + value = as.logical(input$update) + ) + }) + +} + +if (interactive()) + shinyApp(ui, server) diff --git a/man/prettyCheckbox.Rd b/man/prettyCheckbox.Rd index 07c67a31..eae9899e 100644 --- a/man/prettyCheckbox.Rd +++ b/man/prettyCheckbox.Rd @@ -63,8 +63,6 @@ Due to the nature of different checkbox design, certain animations are not appli You can find examples on the pretty-checkbox official page : \url{https://lokesh-coder.github.io/pretty-checkbox/}. } \examples{ -if (interactive()) { - library(shiny) library(shinyWidgets) @@ -75,32 +73,51 @@ ui <- fluidPage( fluidRow( column( width = 4, - prettyCheckbox(inputId = "checkbox1", - label = "Click me!"), + prettyCheckbox( + inputId = "checkbox1", + label = "Click me!" + ), verbatimTextOutput(outputId = "res1"), br(), - prettyCheckbox(inputId = "checkbox4", label = "Click me!", - outline = TRUE, - plain = TRUE, icon = icon("thumbs-up")), + prettyCheckbox( + inputId = "checkbox4", + label = "Click me!", + outline = TRUE, + plain = TRUE, + icon = icon("thumbs-up") + ), verbatimTextOutput(outputId = "res4") ), column( width = 4, - prettyCheckbox(inputId = "checkbox2", - label = "Click me!", thick = TRUE, - animation = "pulse", status = "info"), + prettyCheckbox( + inputId = "checkbox2", + label = "Click me!", + thick = TRUE, + animation = "pulse", + status = "info" + ), verbatimTextOutput(outputId = "res2"), br(), - prettyCheckbox(inputId = "checkbox5", - label = "Click me!", icon = icon("check"), - animation = "tada", status = "default"), + prettyCheckbox( + inputId = "checkbox5", + label = "Click me!", + icon = icon("check"), + animation = "tada", + status = "default" + ), verbatimTextOutput(outputId = "res5") ), column( width = 4, - prettyCheckbox(inputId = "checkbox3", label = "Click me!", - shape = "round", status = "danger", - fill = TRUE, value = TRUE), + prettyCheckbox( + inputId = "checkbox3", + label = "Click me!", + shape = "round", + status = "danger", + fill = TRUE, + value = TRUE + ), verbatimTextOutput(outputId = "res3") ) ) @@ -117,7 +134,9 @@ server <- function(input, output, session) { } -shinyApp(ui, server) +if (interactive()) + shinyApp(ui, server) + @@ -126,53 +145,65 @@ shinyApp(ui, server) ui <- fluidPage( tags$h1("Pretty checkbox: inline example"), br(), - prettyCheckbox(inputId = "checkbox1", - label = "Click me!", - status = "success", - outline = TRUE, - inline = TRUE), - prettyCheckbox(inputId = "checkbox2", - label = "Click me!", - thick = TRUE, - shape = "curve", - animation = "pulse", - status = "info", - inline = TRUE), - prettyCheckbox(inputId = "checkbox3", - label = "Click me!", - shape = "round", - status = "danger", - value = TRUE, - inline = TRUE), - prettyCheckbox(inputId = "checkbox4", - label = "Click me!", - outline = TRUE, - plain = TRUE, - animation = "rotate", - icon = icon("thumbs-up"), - inline = TRUE), - prettyCheckbox(inputId = "checkbox5", - label = "Click me!", - icon = icon("check"), - animation = "tada", - status = "primary", - inline = TRUE), + prettyCheckbox( + inputId = "checkbox1", + label = "Click me!", + status = "success", + outline = TRUE, + inline = TRUE + ), + prettyCheckbox( + inputId = "checkbox2", + label = "Click me!", + thick = TRUE, + shape = "curve", + animation = "pulse", + status = "info", + inline = TRUE + ), + prettyCheckbox( + inputId = "checkbox3", + label = "Click me!", + shape = "round", + status = "danger", + value = TRUE, + inline = TRUE + ), + prettyCheckbox( + inputId = "checkbox4", + label = "Click me!", + outline = TRUE, + plain = TRUE, + animation = "rotate", + icon = icon("thumbs-up"), + inline = TRUE + ), + prettyCheckbox( + inputId = "checkbox5", + label = "Click me!", + icon = icon("check"), + animation = "tada", + status = "primary", + inline = TRUE + ), verbatimTextOutput(outputId = "res") ) server <- function(input, output, session) { - output$res <- renderPrint(c(input$checkbox1, - input$checkbox2, - input$checkbox3, - input$checkbox4, - input$checkbox5)) + output$res <- renderPrint( + c(input$checkbox1, + input$checkbox2, + input$checkbox3, + input$checkbox4, + input$checkbox5) + ) } -shinyApp(ui, server) +if (interactive()) + shinyApp(ui, server) -} } \seealso{ See \code{\link{updatePrettyCheckbox}} to update the value server-side. See \code{\link{prettySwitch}} and diff --git a/man/prettyCheckboxGroup.Rd b/man/prettyCheckboxGroup.Rd index bcf0fa9f..64279915 100644 --- a/man/prettyCheckboxGroup.Rd +++ b/man/prettyCheckboxGroup.Rd @@ -75,8 +75,6 @@ server will receive the input as a character vector of the selected values. } \examples{ -if (interactive()) { - library(shiny) library(shinyWidgets) @@ -87,37 +85,56 @@ ui <- fluidPage( fluidRow( column( width = 4, - prettyCheckboxGroup(inputId = "checkgroup1", - label = "Click me!", - choices = c("Click me !", "Me !", "Or me !")), + prettyCheckboxGroup( + inputId = "checkgroup1", + label = "Click me!", + choices = c("Click me !", "Me !", "Or me !") + ), verbatimTextOutput(outputId = "res1"), br(), - prettyCheckboxGroup(inputId = "checkgroup4", label = "Click me!", - choices = c("Click me !", "Me !", "Or me !"), - outline = TRUE, - plain = TRUE, icon = icon("thumbs-up")), + prettyCheckboxGroup( + inputId = "checkgroup4", + label = "Click me!", + choices = c("Click me !", "Me !", "Or me !"), + outline = TRUE, + plain = TRUE, + icon = icon("thumbs-up") + ), verbatimTextOutput(outputId = "res4") ), column( width = 4, - prettyCheckboxGroup(inputId = "checkgroup2", - label = "Click me!", thick = TRUE, - choices = c("Click me !", "Me !", "Or me !"), - animation = "pulse", status = "info"), + prettyCheckboxGroup( + inputId = "checkgroup2", + label = "Click me!", + thick = TRUE, + choices = c("Click me !", "Me !", "Or me !"), + animation = "pulse", + status = "info" + ), verbatimTextOutput(outputId = "res2"), br(), - prettyCheckboxGroup(inputId = "checkgroup5", - label = "Click me!", icon = icon("check"), - choices = c("Click me !", "Me !", "Or me !"), - animation = "tada", status = "default"), + prettyCheckboxGroup( + inputId = "checkgroup5", + label = "Click me!", + icon = icon("check"), + choices = c("Click me !", "Me !", "Or me !"), + animation = "tada", + status = "default" + ), verbatimTextOutput(outputId = "res5") ), column( width = 4, - prettyCheckboxGroup(inputId = "checkgroup3", label = "Click me!", - choices = c("Click me !", "Me !", "Or me !"), - shape = "round", status = "danger", - fill = TRUE, inline = TRUE), + prettyCheckboxGroup( + inputId = "checkgroup3", + label = "Click me!", + choices = c("Click me !", "Me !", "Or me !"), + shape = "round", + status = "danger", + fill = TRUE, + inline = TRUE + ), verbatimTextOutput(outputId = "res3") ) ) @@ -134,9 +151,9 @@ server <- function(input, output, session) { } -shinyApp(ui, server) +if (interactive()) + shinyApp(ui, server) -} } \seealso{ \code{\link{updatePrettyCheckboxGroup}} for updating values server-side. diff --git a/man/prettyRadioButtons.Rd b/man/prettyRadioButtons.Rd index 203ad96b..8067b616 100644 --- a/man/prettyRadioButtons.Rd +++ b/man/prettyRadioButtons.Rd @@ -73,8 +73,6 @@ A character vector or \code{NULL} server-side. Create a set of radio buttons used to select an item from a list. } \examples{ -if (interactive()) { - library(shiny) library(shinyWidgets) @@ -85,37 +83,56 @@ ui <- fluidPage( fluidRow( column( width = 4, - prettyRadioButtons(inputId = "radio1", - label = "Click me!", - choices = c("Click me !", "Me !", "Or me !")), + prettyRadioButtons( + inputId = "radio1", + label = "Click me!", + choices = c("Click me !", "Me !", "Or me !") + ), verbatimTextOutput(outputId = "res1"), br(), - prettyRadioButtons(inputId = "radio4", label = "Click me!", - choices = c("Click me !", "Me !", "Or me !"), - outline = TRUE, - plain = TRUE, icon = icon("thumbs-up")), + prettyRadioButtons( + inputId = "radio4", + label = "Click me!", + choices = c("Click me !", "Me !", "Or me !"), + outline = TRUE, + plain = TRUE, + icon = icon("thumbs-up") + ), verbatimTextOutput(outputId = "res4") ), column( width = 4, - prettyRadioButtons(inputId = "radio2", - label = "Click me!", thick = TRUE, - choices = c("Click me !", "Me !", "Or me !"), - animation = "pulse", status = "info"), + prettyRadioButtons( + inputId = "radio2", + label = "Click me!", + thick = TRUE, + choices = c("Click me !", "Me !", "Or me !"), + animation = "pulse", + status = "info" + ), verbatimTextOutput(outputId = "res2"), br(), - prettyRadioButtons(inputId = "radio5", - label = "Click me!", icon = icon("check"), - choices = c("Click me !", "Me !", "Or me !"), - animation = "tada", status = "default"), + prettyRadioButtons( + inputId = "radio5", + label = "Click me!", + icon = icon("check"), + choices = c("Click me !", "Me !", "Or me !"), + animation = "tada", + status = "default" + ), verbatimTextOutput(outputId = "res5") ), column( width = 4, - prettyRadioButtons(inputId = "radio3", label = "Click me!", - choices = c("Click me !", "Me !", "Or me !"), - shape = "round", status = "danger", - fill = TRUE, inline = TRUE), + prettyRadioButtons( + inputId = "radio3", + label = "Click me!", + choices = c("Click me !", "Me !", "Or me !"), + shape = "round", + status = "danger", + fill = TRUE, + inline = TRUE + ), verbatimTextOutput(outputId = "res3") ) ) @@ -132,7 +149,6 @@ server <- function(input, output, session) { } -shinyApp(ui, server) - -} +if (interactive()) + shinyApp(ui, server) } diff --git a/man/prettySwitch.Rd b/man/prettySwitch.Rd index 52553371..8d740185 100644 --- a/man/prettySwitch.Rd +++ b/man/prettySwitch.Rd @@ -45,8 +45,6 @@ A toggle switch to replace checkbox Appearance is better in a browser such as Chrome than in RStudio Viewer } \examples{ -if (interactive()) { - library(shiny) library(shinyWidgets) @@ -60,23 +58,29 @@ ui <- fluidPage( prettySwitch(inputId = "switch1", label = "Default:"), verbatimTextOutput(outputId = "res1"), br(), - prettySwitch(inputId = "switch4", - label = "Fill switch with status:", - fill = TRUE, status = "primary"), + prettySwitch( + inputId = "switch4", + label = "Fill switch with status:", + fill = TRUE, status = "primary" + ), verbatimTextOutput(outputId = "res4") ), column( width = 4, - prettySwitch(inputId = "switch2", - label = "Danger status:", - status = "danger"), + prettySwitch( + inputId = "switch2", + label = "Danger status:", + status = "danger" + ), verbatimTextOutput(outputId = "res2") ), column( width = 4, - prettySwitch(inputId = "switch3", - label = "Slim switch:", - slim = TRUE), + prettySwitch( + inputId = "switch3", + label = "Slim switch:", + slim = TRUE + ), verbatimTextOutput(outputId = "res3") ) ) @@ -92,9 +96,8 @@ server <- function(input, output, session) { } -shinyApp(ui, server) - -} +if (interactive()) + shinyApp(ui, server) } \seealso{ See \code{\link{updatePrettySwitch}} to update the value server-side. diff --git a/man/prettyToggle.Rd b/man/prettyToggle.Rd index 1e905a56..276c0926 100644 --- a/man/prettyToggle.Rd +++ b/man/prettyToggle.Rd @@ -69,7 +69,6 @@ you can use Bootstrap status like 'info', 'primary', 'danger', 'warning' or 'suc A single checkbox that changes appearance if checked or not. } \examples{ -if (interactive()) { library(shiny) library(shinyWidgets) @@ -80,31 +79,39 @@ ui <- fluidPage( fluidRow( column( width = 4, - prettyToggle(inputId = "toggle1", - label_on = "Checked!", - label_off = "Unchecked..."), + prettyToggle( + inputId = "toggle1", + label_on = "Checked!", + label_off = "Unchecked..." + ), verbatimTextOutput(outputId = "res1"), br(), - prettyToggle(inputId = "toggle4", label_on = "Yes!", - label_off = "No..", outline = TRUE, - plain = TRUE, - icon_on = icon("thumbs-up"), - icon_off = icon("thumbs-down")), + prettyToggle( + inputId = "toggle4", label_on = "Yes!", + label_off = "No..", outline = TRUE, + plain = TRUE, + icon_on = icon("thumbs-up"), + icon_off = icon("thumbs-down") + ), verbatimTextOutput(outputId = "res4") ), column( width = 4, - prettyToggle(inputId = "toggle2", - label_on = "Yes!", icon_on = icon("check"), - status_on = "info", status_off = "warning", - label_off = "No..", icon_off = icon("remove")), + prettyToggle( + inputId = "toggle2", + label_on = "Yes!", icon_on = icon("check"), + status_on = "info", status_off = "warning", + label_off = "No..", icon_off = icon("remove") + ), verbatimTextOutput(outputId = "res2") ), column( width = 4, - prettyToggle(inputId = "toggle3", label_on = "Yes!", - label_off = "No..", shape = "round", - fill = TRUE, value = TRUE), + prettyToggle( + inputId = "toggle3", label_on = "Yes!", + label_off = "No..", shape = "round", + fill = TRUE, value = TRUE + ), verbatimTextOutput(outputId = "res3") ) ) @@ -120,49 +127,58 @@ server <- function(input, output, session) { } -shinyApp(ui, server) +if (interactive()) + shinyApp(ui, server) -# Inline example ---- +# Inline example ---- ui <- fluidPage( tags$h1("Pretty toggles: inline example"), br(), - prettyToggle(inputId = "toggle1", - label_on = "Checked!", - label_off = "Unchecked...", - inline = TRUE), - prettyToggle(inputId = "toggle2", - label_on = "Yep", - status_on = "default", - icon_on = icon("ok-circle", lib = "glyphicon"), - label_off = "Nope", - status_off = "default", - icon_off = icon("remove-circle", lib = "glyphicon"), - plain = TRUE, - inline = TRUE), - prettyToggle(inputId = "toggle3", - label_on = "", - label_off = "", - icon_on = icon("volume-up", lib = "glyphicon"), - icon_off = icon("volume-off", lib = "glyphicon"), - status_on = "primary", - status_off = "default", - plain = TRUE, - outline = TRUE, - bigger = TRUE, - inline = TRUE), - prettyToggle(inputId = "toggle4", - label_on = "Yes!", - label_off = "No..", - outline = TRUE, - plain = TRUE, - icon_on = icon("thumbs-up"), - icon_off = icon("thumbs-down"), - inline = TRUE), + prettyToggle( + inputId = "toggle1", + label_on = "Checked!", + label_off = "Unchecked...", + inline = TRUE + ), + prettyToggle( + inputId = "toggle2", + label_on = "Yep", + status_on = "default", + icon_on = icon("ok-circle", lib = "glyphicon"), + label_off = "Nope", + status_off = "default", + icon_off = icon("remove-circle", lib = "glyphicon"), + plain = TRUE, + inline = TRUE + ), + prettyToggle( + inputId = "toggle3", + label_on = "", + label_off = "", + icon_on = icon("volume-up", lib = "glyphicon"), + icon_off = icon("volume-off", lib = "glyphicon"), + status_on = "primary", + status_off = "default", + plain = TRUE, + outline = TRUE, + bigger = TRUE, + inline = TRUE + ), + prettyToggle( + inputId = "toggle4", + label_on = "Yes!", + label_off = "No..", + outline = TRUE, + plain = TRUE, + icon_on = icon("thumbs-up"), + icon_off = icon("thumbs-down"), + inline = TRUE + ), verbatimTextOutput(outputId = "res") @@ -170,16 +186,17 @@ ui <- fluidPage( server <- function(input, output, session) { - output$res <- renderPrint(c(input$toggle1, - input$toggle2, - input$toggle3, - input$toggle4)) + output$res <- renderPrint( + c(input$toggle1, + input$toggle2, + input$toggle3, + input$toggle4) + ) } -shinyApp(ui, server) - -} +if (interactive()) + shinyApp(ui, server) } \seealso{ See \code{\link{updatePrettyToggle}} to update the value server-side. diff --git a/man/updatePrettyCheckbox.Rd b/man/updatePrettyCheckbox.Rd index 8e216ee9..78561deb 100644 --- a/man/updatePrettyCheckbox.Rd +++ b/man/updatePrettyCheckbox.Rd @@ -19,8 +19,6 @@ updatePrettyCheckbox(session, inputId, label = NULL, value = NULL) Change the value of a pretty checkbox on the client } \examples{ -if (interactive()) { - library(shiny) library(shinyWidgets) @@ -28,12 +26,17 @@ ui <- fluidPage( tags$h1("Pretty checkbox update value"), br(), - prettyCheckbox(inputId = "checkbox1", - label = "Update me!", - shape = "curve", thick = TRUE, outline = TRUE), + prettyCheckbox( + inputId = "checkbox1", + label = "Update me!", + shape = "curve", + thick = TRUE, + outline = TRUE + ), verbatimTextOutput(outputId = "res1"), radioButtons( - inputId = "update", label = "Value to set:", + inputId = "update", + label = "Value to set:", choices = c("FALSE", "TRUE") ) @@ -44,14 +47,15 @@ server <- function(input, output, session) { output$res1 <- renderPrint(input$checkbox1) observeEvent(input$update, { - updatePrettyToggle(session = session, - inputId = "checkbox1", - value = as.logical(input$update)) + updatePrettyCheckbox( + session = session, + inputId = "checkbox1", + value = as.logical(input$update) + ) }) } -shinyApp(ui, server) - -} +if (interactive()) + shinyApp(ui, server) } diff --git a/man/updatePrettyCheckboxGroup.Rd b/man/updatePrettyCheckboxGroup.Rd index cb5828e4..6df3103a 100644 --- a/man/updatePrettyCheckboxGroup.Rd +++ b/man/updatePrettyCheckboxGroup.Rd @@ -35,14 +35,13 @@ parameters like \code{status}, \code{shape}, ... on the checkboxes, you can re-s \item{choiceValues}{The choices values to set for the input object.} -\item{prettyOptions}{Arguments passed to \code{\link{prettyCheckboxGroup}} for styling checkboxes.} +\item{prettyOptions}{Arguments passed to \code{\link{prettyCheckboxGroup}} +for styling checkboxes. This can be needed if you update choices.} } \description{ Change the value of a pretty checkbox on the client } \examples{ -if (interactive()) { - library(shiny) library(shinyWidgets) @@ -53,11 +52,13 @@ ui <- fluidPage( fluidRow( column( width = 6, - prettyCheckboxGroup(inputId = "checkgroup1", - label = "Update my value!", - choices = month.name[1:4], - status = "danger", - icon = icon("remove")), + prettyCheckboxGroup( + inputId = "checkgroup1", + label = "Update my value!", + choices = month.name[1:4], + status = "danger", + icon = icon("remove") + ), verbatimTextOutput(outputId = "res1"), br(), checkboxGroupInput( @@ -67,10 +68,14 @@ ui <- fluidPage( ), column( width = 6, - prettyCheckboxGroup(inputId = "checkgroup2", - label = "Update my choices!", thick = TRUE, - choices = month.name[1:4], - animation = "pulse", status = "info"), + prettyCheckboxGroup( + inputId = "checkgroup2", + label = "Update my choices!", + thick = TRUE, + choices = month.name[1:4], + animation = "pulse", + status = "info" + ), verbatimTextOutput(outputId = "res2"), br(), actionButton(inputId = "update2", label = "Update choices !") @@ -89,20 +94,26 @@ server <- function(input, output, session) { } else { selected_ <- input$update1 } - updatePrettyCheckboxGroup(session = session, inputId = "checkgroup1", selected = selected_) + updatePrettyCheckboxGroup( + session = session, + inputId = "checkgroup1", + selected = selected_ + ) }, ignoreNULL = FALSE) output$res2 <- renderPrint(input$checkgroup2) observeEvent(input$update2, { updatePrettyCheckboxGroup( - session = session, inputId = "checkgroup2", - choices = sample(month.name, 4), prettyOptions = list(animation = "pulse", status = "info") + session = session, + inputId = "checkgroup2", + choices = sample(month.name, 4), + prettyOptions = list(animation = "pulse", status = "info") ) }, ignoreInit = TRUE) } -shinyApp(ui, server) +if (interactive()) + shinyApp(ui, server) } -} diff --git a/man/updatePrettyRadioButtons.Rd b/man/updatePrettyRadioButtons.Rd index f0c7ee88..d561a7ff 100644 --- a/man/updatePrettyRadioButtons.Rd +++ b/man/updatePrettyRadioButtons.Rd @@ -35,14 +35,13 @@ parameters like \code{status}, \code{shape}, ... on the radio buttons, you can r \item{choiceValues}{The choices values to set for the input object.} -\item{prettyOptions}{Arguments passed to \code{\link{prettyRadioButtons}} for styling radio buttons} +\item{prettyOptions}{Arguments passed to \code{\link{prettyRadioButtons}} +for styling radio buttons. This can be needed if you update choices.} } \description{ Change the value pretty radio buttons on the client } \examples{ - if (interactive()) { - library(shiny) library(shinyWidgets) @@ -53,11 +52,13 @@ ui <- fluidPage( fluidRow( column( width = 6, - prettyRadioButtons(inputId = "radio1", - label = "Update my value!", - choices = month.name[1:4], - status = "danger", - icon = icon("remove")), + prettyRadioButtons( + inputId = "radio1", + label = "Update my value!", + choices = month.name[1:4], + status = "danger", + icon = icon("remove") + ), verbatimTextOutput(outputId = "res1"), br(), radioButtons( @@ -67,10 +68,14 @@ ui <- fluidPage( ), column( width = 6, - prettyRadioButtons(inputId = "radio2", - label = "Update my choices!", thick = TRUE, - choices = month.name[1:4], - animation = "pulse", status = "info"), + prettyRadioButtons( + inputId = "radio2", + label = "Update my choices!", + thick = TRUE, + choices = month.name[1:4], + animation = "pulse", + status = "info" + ), verbatimTextOutput(outputId = "res2"), br(), actionButton(inputId = "update2", label = "Update choices !") @@ -94,7 +99,8 @@ server <- function(input, output, session) { output$res2 <- renderPrint(input$radio2) observeEvent(input$update2, { updatePrettyRadioButtons( - session = session, inputId = "radio2", + session = session, + inputId = "radio2", choices = sample(month.name, 4), prettyOptions = list(animation = "pulse", status = "info", @@ -104,7 +110,6 @@ server <- function(input, output, session) { } -shinyApp(ui, server) - - } +if (interactive()) + shinyApp(ui, server) } diff --git a/man/updatePrettySwitch.Rd b/man/updatePrettySwitch.Rd index 4e3a7ed3..92eb5d8c 100644 --- a/man/updatePrettySwitch.Rd +++ b/man/updatePrettySwitch.Rd @@ -19,8 +19,6 @@ updatePrettySwitch(session, inputId, label = NULL, value = NULL) Change the value of a pretty switch on the client } \examples{ -if (interactive()) { - library(shiny) library(shinyWidgets) @@ -31,7 +29,8 @@ ui <- fluidPage( prettySwitch(inputId = "switch1", label = "Update me !"), verbatimTextOutput(outputId = "res1"), radioButtons( - inputId = "update", label = "Value to set:", + inputId = "update", + label = "Value to set:", choices = c("FALSE", "TRUE") ) @@ -42,13 +41,15 @@ server <- function(input, output, session) { output$res1 <- renderPrint(input$switch1) observeEvent(input$update, { - updatePrettySwitch(session = session, inputId = "switch1", - value = as.logical(input$update)) + updatePrettySwitch( + session = session, + inputId = "switch1", + value = as.logical(input$update) + ) }) } -shinyApp(ui, server) - -} +if (interactive()) + shinyApp(ui, server) } diff --git a/man/updatePrettyToggle.Rd b/man/updatePrettyToggle.Rd index 726b64a0..a632b980 100644 --- a/man/updatePrettyToggle.Rd +++ b/man/updatePrettyToggle.Rd @@ -19,8 +19,6 @@ updatePrettyToggle(session, inputId, label = NULL, value = NULL) Change the value of a pretty toggle on the client } \examples{ -if (interactive()) { - library(shiny) library(shinyWidgets) @@ -28,12 +26,15 @@ ui <- fluidPage( tags$h1("Pretty toggle update value"), br(), - prettyToggle(inputId = "toggle1", - label_on = "Checked!", - label_off = "Unchecked..."), + prettyToggle( + inputId = "toggle1", + label_on = "Checked!", + label_off = "Unchecked..." + ), verbatimTextOutput(outputId = "res1"), radioButtons( - inputId = "update", label = "Value to set:", + inputId = "update", + label = "Value to set:", choices = c("FALSE", "TRUE") ) @@ -44,14 +45,15 @@ server <- function(input, output, session) { output$res1 <- renderPrint(input$toggle1) observeEvent(input$update, { - updatePrettyToggle(session = session, - inputId = "toggle1", - value = as.logical(input$update)) + updatePrettyToggle( + session = session, + inputId = "toggle1", + value = as.logical(input$update) + ) }) } -shinyApp(ui, server) - -} +if (interactive()) + shinyApp(ui, server) }