Learn R Programming

yonder (version 0.1.0)

formInput: Form inputs

Description

Form inputs are a new reactive input. Form inputs are an alternative to shiny's submit buttons. A form input is comprised of any number of inputs. The value of these inputs will not change until the form input's submit input is clicked. A form input's reactive value also depends on the submit input. This allows you to distinguish between different clicks if your form includes multiple submit inputs.

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().

If id or submit are NULL the form input will not freeze its child inputs.

Usage

formInput(id, submit, ..., inline = FALSE)

Arguments

id

A character string specifying the id of the reactive input.

submit

A button input, which will trigger the form and cause reactives to update.

...

Any number of unnamed arguments (inputs or tag elements) passed as child elements to the form.

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

inline

One of TRUE or FALSE, if TRUE the form and its child elements are rendered in a horizontal row, defaults to FALSE. On small viewports, think mobile device, inline intentionally has no effect and the form will span multiple lines.

Frozen inputs with scope

ui <- container(
  formInput(
    id = "form",
    formGroup(
      label = "Email",
      emailInput(
        id = "email"
      )
    ),
    formGroup(
      label = "Password",
      passwordInput(
        id = "password"
      )
    )
  )
)

server <- function(input, output) { }

shinyApp(ui, server)

Details

When inline is TRUE you may want to adjust the right margin of each child element for viewports larger than mobile, margin(<TAG>, right = c(sm = 2)), more information at margin(). You only need to apply extra space for larger viewports because inline forms do not take effect on small viewports.

See Also

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

Examples

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

card(
  header = "Please pick a flavor",
  formInput(
    id = NULL,
    formGroup(
      label = "Ice creams",
      radioInput(
        id = "flavorChoice",
        choices = c("Mint", "Moose tracks", "Marble"),
      )
    ),
    submit = buttonInput(  # <-
      id = NULL,
      label = "Make choice"
    ) %>%
      background("teal")
  )
) %>%
  border("teal") %>%
  width(50)

# }

Run the code above in your browser using DataLab