Skip to content

Conversation

cpsievert
Copy link
Collaborator

Work in progress that will depend on incoming changes to Shiny.

If anyone is curious to see examples, here are a couple basic ones:

app-submit-text.R
library(shiny)
library(bslib)

ui <- page_sidebar(
  title = "Hello input_submit_textarea()",
  input_dark_mode(),
  input_submit_textarea(
    "text",
    "Enter input to submit",
    label = tags$code("bslib::input_submit_textarea()"),
  ),
  textOutput("value"),
  textAreaInput(
    "update_text",
    tags$code("shiny::textAreaInput()"),
    placeholder = "Enter text for updating the input above",
    autoresize = TRUE
  ),
  actionButton("update", "Update"),
  actionButton("focus", "Update & Focus"),
  actionButton("submit", "Submit"),
  actionButton("update_label", "Update Label"),
  shiny::useBusyIndicators(),
  sidebar = sidebar(open = FALSE),
  class = "align-items-center"
)
server <- function(input, output, session) {

  output$value <- renderText({
    req(input$text)
    Sys.sleep(3)
    paste("You entered:", input$text)
  })

  observeEvent(input$update, {
    update_submit_textarea("text", value = input$update_text)
  })

  observeEvent(input$focus, {
    update_submit_textarea("text", value = input$update_text, focus = TRUE)
  })

  observeEvent(input$submit, {
    update_submit_textarea("text", value = input$update_text, submit = TRUE)
  })

  observeEvent(input$update_label, {
    update_submit_textarea("text", label = input$update_text)
  })

}

shinyApp(ui, server)
app-submit-button.R
library(shiny)
library(bslib)

ui <- page_sidebar(
  title = "Hello input_submit_button()",
  sidebar = sidebar(
    sliderInput("n", "A number", 1, 100, 10),
    selectInput("letter", "A letter", LETTERS),
    input_submit_button(
      "submit",
      "Submit",
      icon = icon("paper-plane")
    ),
    helpText(
      "Changes to sidebar inputs aren't sent to the server until the submit button is clicked.",
      class = "lead"
    )
  ),
  card(
    card_header("Sidebar input values"),
    verbatimTextOutput("n_out"),
    verbatimTextOutput("letter_out"),
  ),
  card(
    card_header("Other input values"),
    layout_sidebar(
      sidebar = selectInput("state", "A state", state.abb),
      verbatimTextOutput("state_out"),
    )
  ),
  useBusyIndicators()
)
server <- function(input, output, session) {

  output$n_out <- renderText({
    #req(input$submit)
    Sys.sleep(2)
    paste("Number:", input$n)
  })

  output$letter_out <- renderText({
    #req(input$submit)
    Sys.sleep(2)
    paste("Letter:", input$letter)
  })

  output$state_out <- renderText({
    paste("State:", input$state)
  })

}
shinyApp(ui, server)

return $(scope).find(".bslib-input-textsubmit > textarea");
}

initialize(el: HTMLTextAreaElement): void {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure to update height in a similar way to TextAreaInputBinding does now rstudio/shiny#4210

@cpsievert cpsievert force-pushed the feat/submit-input branch from 7aacb20 to 1d69765 Compare July 25, 2025 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant