Learn R Programming

yonder (version 0.1.0)

buttonInput: Button and submit inputs

Description

Button inputs are useful as triggers for reactive or observer expressions. The reactive value of a button input begins as NULL, but subsequently is the number of clicks.

Usage

buttonInput(id, label, ..., stretch = FALSE, download = FALSE)

linkInput(id, ..., stretch = FALSE, download = FALSE)

Arguments

id

A character string specifying the id of the reactive input.

label

A character string specifying the label text on the button input.

...

Additional named arguments passed as HTML attributes to the parent element.

stretch

One of TRUE or FALSE specifying stretched behaviour for the button or link input, defaults to FALSE. If TRUE, the button or link will receive clicks from its containing block element. For example, a stretched button or link inside a card() would update whenever the user clicked on the card.

download

One of TRUE or FALSE specifying if the button or link input is used to trigger a download, defaults to FALSE.

See Also

Other inputs: buttonGroupInput, checkboxInput, chipInput, fileInput, formInput, groupInput, listGroupInput, menuInput, navInput, radioInput, rangeInput, selectInput, sliderInput, textInput

Examples

Run this code
# NOT RUN {
### A simple button

buttonInput(
  id = "button1",
  label = "Simple"
)

# Alternatively, a button can fill the width of its parent element.

buttonInput(
  id = "button2",
  label = "Full-width",
  fill = TRUE  # <-
) %>%
  background("red")

# Use design utilities to further adjust the width of a button.

buttonInput(
  id = "button3",
  label = "Full and back again",
  fill = TRUE  # <-
) %>%
  background("red") %>%
  width("3/4")  # <-

### Possible colors

colors <- c(
  "red", "purple", "indigo", "blue", "cyan", "teal", "green",
  "yellow", "amber", "orange", "grey"
)

lapply(
  colors,
  function(color) {
    buttonInput(
      id = color,
      label = color
    ) %>%
      background(color) %>%
      margin(2)
  }
) %>%
  div() %>%
  display("flex") %>%
  flex(wrap = TRUE)

### Reactive links

div("Curabitur ", linkInput("link1", "vulputate"), " vestibulum lorem.")

### Stretched buttons and links

card(
  header = "Card with stretched button",
  p("Notice when you hover over the card, the button also detects ",
    "the hover."),
  buttonInput(
    id = "go",
    label = "Go go go",
    stretch = TRUE
  ) %>%
    background("blue")
) %>%
  width(20)

### Download button

buttonInput(
  download = TRUE,
  id = "download1",
  label = "Download",
  icon("download")
)

# }

Run the code above in your browser using DataLab