使用 DT,您可以做一些花哨的事情。以下是一个示例,其中表格列出了包含您键入的文本的所有选项。如果单击表格单元格,则文本输入将使用表格单元格的文本进行更新。您也可以使用表格的搜索字段。
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)
}
})
}
)