多行文本输入闪亮 [英] Multi line text inputs in shiny

查看:82
本文介绍了多行文本输入闪亮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在多行/换行(透明显示或仅软包装以在UI中获得更好的输出)的文本输入中,我有哪些选择可以实现?

我想实现一个具有描述/详细信息字段的应用程序,所输入的内容很可能不仅仅是一行.

基本上,我正在寻找实现Stackoverflow文本输入框类似功能的东西,我在用以下方法编写此问题:换行符,滚动条和/或(自动)调整高度.

示例

# 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)

解决方案

尝试使用textAreaInput而不是textInput. 使用前者,您可以设置高度和宽度,如果行太长,它将自动换行到下一行.

此处是在文档中提到的地方. >

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)

解决方案

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.

这篇关于多行文本输入闪亮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆