buttonInput: Button and link inputs

View source: R/input-button.R

buttonInputR Documentation

Button and link 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, tooltip = NULL)

updateButtonInput(
  id,
  label = NULL,
  value = NULL,
  disable = NULL,
  enable = NULL,
  tooltip = NULL,
  session = getDefaultReactiveDomain()
)

linkInput(..., id, label, stretch = FALSE, download = FALSE, tooltip = NULL)

updateLinkInput(
  id,
  label = NULL,
  value = NULL,
  enable = NULL,
  disable = NULL,
  tooltip = NULL,
  session = getDefaultReactiveDomain()
)

tooltip(..., placement = "top", fade = TRUE)

Arguments

...

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

id

A character string specifying the id of the reactive input.

label

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

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.

tooltip

A call to tooltip() specifying a tooltip for the button or link input, defaults to NULL.

value

A number specifying a new value for the button, defaults to NULL.

disable

if TRUE the button is disabled and will not react to clicks from the user, default to NULL.

enable

If TRUE the button is enabled and will react to clicks from the user, defaults to NULL.

session

A reactive context, defaults to getDefaultReactiveDomain().

placement

One of "top", "right", "bottom", or "left" specifying what side of the tag element the tooltip appears on.

fade

One of TRUE or FALSE specifying if the tooltip fades in when shown and fades out when hidden, defaults to TRUE.

Details

Tooltips

To remove a button or link input's tooltip pass an empty tooltip, tooltip(), to updateButtonInput() or updateLinkInput().

Getting started

buttonInput(
  id = NULL,
  label = "Label"
)

Add a little color

buttonInput(
  .style %>%
    background("primary"),
  id = NULL,
  label = "Label"
)

Use the width() utility to adjust the size of a button.

buttonInput(
  .style %>%
    background("danger") %>%
    width(75),  # <-
  id = NULL,
  label = "Label"
)

Reactive links

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

Stretched buttons and links

Use a stretched button to make an entire card clickable.

card(
  .style %>%
    border("primary") %>%
    font("primary"),
  header = "Product summary",
  p("Here is a summary"),
  p("This is a second paragraph"),
  footer = list(
    buttonInput(
      .style %>%
        background("primary"),
      id = "seemore",
      label = "See more",
      stretch = TRUE
    )
  )
)
Product summary

Here is a summary

This is a second paragraph

Notice, when you hover over the card the mouse cursor changes and the button appears hovered. The card is now passing clicks on to the button. Clicking anywhere on the card will trigger a click on the button.

card(
  header = "Card with stretched button",
  p("Notice when you hover over the card, the button also detects ",
    "the hover."),
  buttonInput(
    .style %>%
      background("primary"),
    id = NULL,
    label = "Label",
    stretch = TRUE
  )
)
Card with stretched button

Notice when you hover over the card, the button also detects the hover.

Download button

Pair a download button input with shiny::downloadHandler().

buttonInput(
  download = TRUE,  # <-
  id = NULL,
  label = "Download",
  tags$i(class = "fas fa-download")
)
Download

See Also

Other inputs: buttonGroupInput(), checkbarInput(), checkboxInput(), chipInput(), fileInput(), formInput(), listGroupInput(), menuInput(), navInput(), radioInput(), radiobarInput(), rangeInput(), selectInput(), textInput()


nteetor/dull documentation built on June 10, 2022, 11:30 a.m.