How to create TextArea as input in a Shiny webapp in R?

前端 未结 6 1783
春和景丽
春和景丽 2020-12-13 00:47

I am trying to create simple webapp where I want to take in multiline input from user using HTML textarea control. Is there any out of the box way of creating such an input

6条回答
  •  时光说笑
    2020-12-13 01:12

    Building off of Joe's answer (https://stackoverflow.com/a/14452837/5776618), you can also nest tags into your own function to achieve the same output as the standard Shiny built-in input functions.

    textareaInput <- function(id, label, value, rows=20, cols=35, class="form-control"){
      tags$div(
        class="form-group shiny-input-container",
        tags$label('for'=id,label),
        tags$textarea(id=id,class=class,rows=rows,cols=cols,value))
      }
    

    This is a way to avoid writing the JS code (if you want to) while still...

    • having a function that calls the same way the built-in Shiny inputs are called, and
    • includes the div, label, and Bootstrap's form-control CSS style (so that it looks like the built-in Shiny input controls)

    Using the function is same as if you are using the built-in or if you built a custom UI.

    textareaInput("textareaID","Text Area Label", "Insert text here...", rows = 20, cols = 35)
    

提交回复
热议问题