Learn R Programming

yonder (version 0.0.5)

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.

A submit input is a special type of button used to control form input submission. Because of their specific usage, submit inputs do not require an id, but may have a specified value. Submit inputs will not freeze all reactive inputs, see formInput().

Usage

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

submitInput(label = "Submit", value = label, ..., fill = FALSE)

linkInput(id, text, ..., stretch = 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.

fill

One of TRUE or FALSE specifying if the button fills the entire width of its parent, defaults to FALSE.

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.

value

A character string specifying the value of a submit input, defaults to label. This value is used to distinguish form submission types in the case where a form input has multiple submit inputs.

text

A character string specifying the text displayed as part of the link input.

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")  # <-

### A submit button

submitInput()

# Or use custom text to clarify the action taken when clicked by the user.

submitInput("Place order")

### 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)

# }

Run the code above in your browser using DataLab