Multi-line textInput?

2,437 views
Skip to first unread message

Yindeng Jiang

unread,
Feb 13, 2015, 1:02:46 AM2/13/15
to shiny-...@googlegroups.com
The textInput in shiny doesn't accept the "return" character. And if I type "\n" in the text box, the slash will be escaped so I end up getting a literal "\\n". Anyone knows a way to get multi-line inputs?

Yindeng

Kevin Lindquist

unread,
Feb 13, 2015, 2:45:12 AM2/13/15
to shiny-...@googlegroups.com
Hello Yindeng,

You can use a textarea tag to get multi-line text input. For example,

ui.R

library(shiny)

shinyUI(
    fluidPage(
        h4("Multi-line text input test"),
        tags$style(type="text/css", "textarea {width:100%}"),
        tags$textarea(id = 'input_text', placeholder = 'Type here', rows = 8, ""),
        verbatimTextOutput("output_text")
    )
)


server.R


library(shiny)

shinyServer(
    function(input, output){
        output$output_text <- reactive({
            input$input_text
        })
    }
)


Kevin

Vivek Patil

unread,
Feb 13, 2015, 8:47:32 AM2/13/15
to Yindeng Jiang, shiny-...@googlegroups.com
See this question on SO and the responses it received for an answer to your question: http://stackoverflow.com/questions/14452465/how-to-create-textarea-as-input-in-a-shiny-webapp-in-r


On Thu, Feb 12, 2015 at 10:02 PM, Yindeng Jiang <jiangy...@gmail.com> wrote:
The textInput in shiny doesn't accept the "return" character. And if I type "\n" in the text box, the slash will be escaped so I end up getting a literal "\\n". Anyone knows a way to get multi-line inputs?

Yindeng

--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/12b6af71-2a76-40b3-88d7-1e992e0690cd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Yindeng Jiang

unread,
Feb 13, 2015, 12:43:38 PM2/13/15
to shiny-...@googlegroups.com
Thank you. This worked great! I created a wrapper as below in case it's useful for others:

textareaInput <- function(inputId, label, value="", placeholder="", rows=2){
  tagList(
    div(strong(label), style="margin-top: 5px;"),
    tags$style(type="text/css", "textarea {width:100%; margin-top: 5px;}"),
    tags$textarea(id = inputId, placeholder = placeholder, rows = rows, value))
}

Yindeng
Reply all
Reply to author
Forward
0 new messages