【发布时间】:2021-11-16 19:57:15
【问题描述】:
我正在尝试构建一个闪亮的应用程序,以便用户可以与我在数据框中的一组句子“交互”。数据框如下所示:
# id: each sentence has a unique number
# file: name of the file the sentence comes from
# sentence: the actual sentence
# group: group the writer belongs to
# gender: writer's gender
id file sentence group gender
1 101s the tree is tall. A female
2 101s the sun is yellow. A female
3 102s he reads a book. D male
4 102s she goes shopping. D male
5 103s they drive the car. B female
...
我想使用 R Shiny 创建一个“上下文中的关键字”搜索栏。基本上,用户输入一个词,应用程序就会检索包含该词的句子。
这是我在ui.R 文件中包含的用于特定目的的代码:
sidebarPanel(
textInput("Input_KWIC", "Enter a keyword:"),
mainPanel(htmlOutput("Text_KWIC")))),
这是我包含在server.R 文件中的代码。
output$Text_KWIC = renderUI({
data %>%
filter(grepl(input$Input_KWIC, sentence)) %>%
pull(sentence)
})
当我运行应用程序时,我收到此错误:“要写入的文本必须是长度为 1 的字符向量”(这是在我输入关键字之后)。
我不知道我做错了什么,也不知道错误是在 UI 中还是在服务器中。
【问题讨论】:
-
你说的好像是在
DT::datatable实现的,你试过了吗? -
我对按照我描述的方式进行操作很感兴趣。我不希望输出是一个表格,而是一个句子列表。