简体   繁体   English

闪亮-textInput

[英]Shiny - textInput

Is there any way that we can provide available options while using textInput in shiny similar to shiny selectinput option? 在闪亮的情况下使用textInput类似于闪亮的selectinput选项,有什么方法可以提供可用选项?

That is, if a user types a letter or character, all available options within the letter or character must be provided. 也就是说,如果用户键入字母或字符,则必须提供字母或字符内的所有可用选项。 Since I have a lot of options, selectinput kind of slows down and not a good option for the input. 由于我有很多选择,因此selectinput会减慢速度,对于输入而言不是一个好的选择。 Therefore, I opt for textInput. 因此,我选择textInput。

Any suggestions will be helpful! 任何建议都会有所帮助!

Thanks 谢谢

You can use selectInput with argument multiple = TRUE 您可以将selectInput与参数multiple = TRUE一起使用

selectInput(inputId, label, choices, multiple = TRUE)

This will output a text box rather than drop down and as user starts typing all the available options within the letter will be filtered. 这将输出一个文本框,而不是下拉列表,并且当用户开始键入字母时,所有可用选项都将被过滤。

Create a select list input control 创建选择列表输入控件

Example

using DT, you can do some fancy stuff. 使用DT,您可以做一些花哨的事情。 Following is an example where the table lists all the options that contain the text you typed. 下面是一个示例,该表列出了包含您键入的文本的所有选项。 If you click on a table cell, the text input is updated with the table cell's text. 如果单击表格单元格,则使用表格单元格的文本更新文本输入。 You can also use the search field of the table. 您也可以使用表格的搜索字段。

library(shiny)

shinyApp(
  ui = fluidPage(textInput("text", "Please input text:"),
                 DT::dataTableOutput('tbl')),

  server = function(session, input, output) {

    # all your choices for the textfield go into "text" column
    allData <- data.frame(ID = '', text = c(paste0("Text",1:50)))

    # table with only the texts that contain input$text
    output$tbl = DT::renderDataTable(
      allData[grep(input$text, allData$text), ],
      selection = 'none',
      rownames = FALSE,
      options = list(searchHighlight=T)
    )

    # fill textInput after Click in Table
    observeEvent(input$tbl_cell_clicked, {
      info <- input$tbl_cell_clicked

      if (is.null(info$value) || info$col != 1) return()
      else {
       updateTextInput(session, "text", value = info$value)
      }
    })
  }
)

在此处输入图片说明

selectinput kind of slows down and not a good option for the input selectinput会减慢速度,不是输入的好选择

selectInput with multiple choice is the best option in this case. 在这种情况下,带有多个选择的selectInput是最佳选项。 The slow loading can be easily managed by moving selectInput into server. 通过将selectInput移入服务器,可以轻松管理缓慢的加载。

Just type in ui.R : 只需输入ui.R

selectizeInput(inputId=..., label=..., choices = NULL, multiple = TRUE)

and in server.R : 并在server.R

server <-  function(input, output, session) {
    updateSelectizeInput(session = session,inputId =...,choices=..., server = TRUE)}

Now You should not have any problems with slow loading. 现在,慢速加载应该不会有任何问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM