textButton: Text input with an action button

Description Usage Arguments Value Examples

View source: R/inputs.R

Description

One kind of bootstrap3 input group: a textinput and a button attached to the end

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
textButton(
  textId,
  btnId = paste0(textId, "_btn"),
  label = "",
  text_value = "",
  placeholder = "",
  tooltip = "",
  placement = "bottom",
  btn_icon = NULL,
  btn_label = "btn",
  style = "",
  ...
)

Arguments

textId

the text input ID

btnId

the button ID, if not specified, it is "textId" + "_btn" like, textId_btn

label

label of the whole group, on the top

text_value

initial value of the text input

placeholder

placeholder text of the text input

tooltip

a tooltip of the group

placement

where should the tooltip go?

btn_icon

a shiny::icon of the button

btn_label

text on the button

style

additional CSS style of the group

...

additional args pass to the button, see shiny::actionButton

Value

a shiny input group

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
38
if(interactive()){
  library(shiny)

  ui <- fluidPage(
    column(
      6,
      textButton(textId = "tbtn_default", label = "default"),
      textButton(
        textId = "tbtn-icon",
        label = "change icon and color",
        btn_icon = icon("home"),
        class = "btn-warning" # pass to the button
      ),
      textButton(
        textId = "tbtn_style",
        label = "change styles",
        style = "color: red; border: 2px dashed green;"
      ),
      textButton(
        textId = "tbtn_submit",
        label = "interact with shiny server",
        btn_label = "Submit",
        placeholder = "type and submit",
        class = "btn-primary"),
      verbatimTextOutput("tbtn_submit_out")
    )
  )

  server <- function(input, output, session) {
    # watch for the button ID "tbtn_submit" + "_btn"
    observeEvent(input$tbtn_submit_btn, {
      output$tbtn_submit_out <- renderPrint(isolate(input$tbtn_submit))
    })

  }

  shinyApp(ui, server)
}

spsComps documentation built on Feb. 3, 2022, 1:07 a.m.