我正在构建一个闪亮的应用程序,它接受用户的文本输入,将最后两个单词与三元组的数据帧进行比较,以预测最可能的下一个单词。在server.R中,我正在尝试输出的triPred函数的输出是一个单词。当我加载这个应用程序时,我在应用程序中键入一些文本后得到以下错误-‘参数1(类型’闭包‘)无法由'cat’处理-这似乎与server.R中的最后一行相关。R因为这只是一个单词,我不清楚'cat‘ie连接失败的原因是什么。
server.R
library(stringr)
shinyServer(function(input, output) {
triSplit <- function(input) {
el <- unlist(str_split(input," "))
bigram <- paste(el[length(el)-1],el[length(el)])
return(bigram)
}
triPred <- function(input) {
## pulls out end words that match the input bigram
temp_wf_T <- wf_T[wf_T$start == triSplit(input),]
##Picks one of the best options at random based on count
ans <- sample(temp_wf_T$end[temp_wf_T$count == max(temp_wf_T$count)],1)
return(ans) }
##Read in a dataframe of bigrams, their possible completions, and counts of occurence
wf_T<-readRDS("C:/Users/LTM/DataScienceCertificateCapstone/ShinyTest/data/tdm.rds")
##Runs the triPred function to guess the next most likely word
ans <- reactive(triPred(input$sent))
##generates an output variable to display
output$out <- renderText({ans})
})ui.R
library(shiny)
shinyUI(fluidPage(
titlePanel(h1("My Shiny App", align = "center")),
sidebarLayout(
sidebarPanel(helpText("Please enter a sentence you would like me to complete"),
textInput("sent", label = "sentence")),
##########
mainPanel(h1("Best Guess"),
br(),
textOutput("out")
)
)
))发布于 2016-04-10 04:18:04
很难说,因为我不能复制你的应用程序,但你应该尝试一下:
output$out <- renderText({ans()})或直接使用output$out <- renderText(ans())。
如果您省略了(),您将访问反应本身,而不是它的值。这有点像在函数中输入foo而不是foo()。
https://stackoverflow.com/questions/36522095
复制相似问题