Rappster
Rappster

Reputation: 13100

Multi line text inputs in shiny

What are my options to realize text inputs with multiple lines/line breaks (either explicit or just soft-wraps for nicer output in the UI) in shiny?

I'd like to implement an app that has a description/details field and the content being entered will most likely be more than just one line.

Basically, I'm looking for something to realize a similar functionality of the very text input box of stackoverflow I'm writing this question in: line breaks, scroll bar and/or (auto-)adjustment of height.

Example

# UI ---------------------------------------------------------------------

ui <- fluidPage(
  p(),
  textInput("title", "Title"),
  textInput("description", "Description"),
  tags$hr(),
  h3("Database state"),
  DT::dataTableOutput("datatable")
)

# Server ------------------------------------------------------------------

server <- function(input, output, session) {
  output$datatable <- DT::renderDataTable(
    data.frame(
      Title = input$title,
      Description = input$description,
      stringsAsFactors = FALSE
    )
  )
}

shinyApp(ui, server)

Upvotes: 14

Views: 10078

Answers (1)

Ike
Ike

Reputation: 1059

Try using textAreaInput instead of textInput. With the former you can set height and width, and it automatically will wrap to next line if line is too long.

Here is where it is mentioned in the docs.

Upvotes: 15

Related Questions