Submit Button
#| standalone: true
#| components: [viewer]
#| viewerHeight: 200
library(shiny)
library(bslib)
ui <- page_fixed(
layout_columns(
textInput("city", "City", "New York City"),
selectInput("state", "State", choices = state.abb, selected = "NY"),
textInput("zip", "Zip Code", "10006"),
col_widths = breakpoints(sm = c(5, 2, 2))
),
submitButton(text = "Update Address"),
tags$br(),
verbatimTextOutput("display_text")
)
server <- function(input, output) {
output$display_text <- renderText({
paste0(input$city, ", ", input$state, " ", input$zip)
})
}
shinyApp(ui = ui, server = server)
library(shiny)
library(bslib)
ui <- page_fixed(
layout_columns(
textInput("city", "City", "New York City"),
selectInput("state", "State", choices = state.abb, selected = "NY"),
textInput("zip", "Zip Code", "10006"),
col_widths = breakpoints(sm = c(5, 2, 2))
),
submitButton(text = "Update Address"),
tags$br(),
verbatimTextOutput("display_text")
)
server <- function(input, output) {
output$display_text <- renderText({
paste0(input$city, ", ", input$state, " ", input$zip)
})
}
shinyApp(ui = ui, server = server)
Relevant Functions
-
submitButton
submitButton(text = "Apply Changes", icon = NULL, width = NULL)
Details
Apps that include a submit button do not automatically update their outputs when inputs change, rather they wait until the user explicitly clicks the submit button. The use of submitButton()
is generally discouraged in favor of the more versatile actionButton()
.
Follow these steps to add a submit button to your app:
Add
submitButton()
to the UI of your app to create a submit button. Where you call this function will determine where the button will appear within the app’s layout.Provide text to display on the submit button.
(Optionally) set the
width
of the button, or add anicon
, e.g.submitButton("Go", icon = icon("refresh"), width = '400px')
,
Note that a submit button applies globally to an entire Shiny app. The app will not react to any input until the Submit button is clicked. So, for example, you would not include two Submit buttons to control different parts of the app.
Shiny users may not expect the behavior created by a Submit button, so we recommend that you make both the button and its purpose very clear in your app.
See also
- Action Button
- Task Button to launch extended tasks that should run in the background