updatePrettyToggle: Change the value of a pretty toggle on the client

Description Usage Arguments Examples

View source: R/input-pretty.R

Description

Change the value of a pretty toggle on the client

Usage

1
2
3
4
5
6
updatePrettyToggle(
  session = getDefaultReactiveDomain(),
  inputId,
  label = NULL,
  value = NULL
)

Arguments

session

The session object passed to function given to shinyServer.

inputId

The id of the input object.

label

The label to set for the input object.

value

The value to set for the input object.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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)

Example output



shinyWidgets documentation built on Jan. 11, 2022, 1:06 a.m.