【发布时间】:2021-01-17 17:30:58
【问题描述】:
我正在尝试编写一个闪亮的小应用程序。该应用程序的一部分是汇总用户粘贴到框中然后按下操作按钮的文本。 我从一个在线博客复制了文本示例,它在闪亮之外工作
我使用了来自闪亮网站的操作按钮代码
当我运行下面的代码时,我得到了这个错误Error in sentenceParse(text, docId = docId) : text must be character
我猜这可能是因为文本框(n 或 ntext)的输出不是一个因素。所以我尝试使用as.factor(ntext) 进行更改,但仍然没有成功。
感谢任何指导。
谢谢
library(shiny)
library(lexRankr)
#
ui <- fluidPage(
textAreaInput("n", "Paste text and click submit", rows = 5),
br(),
actionButton("goButton", "Go!"),
verbatimTextOutput("nText")
)
#
server <- function(input, output) {
ntext <- eventReactive(input$goButton, {
input$n
})
#perform lexrank for top 3 sentences
top_3 = lexRankr::lexRank(ntext,
docId = rep(1, length(ntext)),
n = 3,
continuous = TRUE)
#reorder the top 3 sentences to be in order of appearance in article
order_of_appearance = order(as.integer(gsub("_","",top_3$sentenceId)))
#extract sentences in order of appearance
ordered_top_3 = top_3[order_of_appearance, "sentence"]
output$nText <- renderText({
ordered_top_3()
})
}
#
shinyApp(ui = ui, server = server)
【问题讨论】:
标签: r shiny action-button