闪亮的应用程序失败并显示 "argument 1 (type 'closure') cannot be handled by 'cat'" - 这是什么意思?
Shiny app fails with "argument 1 (type 'closure') cannot be handled by 'cat'" - what does this mean?
我正在构建一个闪亮的应用程序,它接受用户的文本输入,将最后两个词与三元组数据框进行比较,以预测最有可能出现的下一个词。在 server.R 下面,我试图输出的 triPred 函数的输出是一个单词。当我加载这个应用程序时,我在应用程序中键入一些文本后出现以下错误 - 'argument 1 (type 'closure') cannot be handled by 'cat' - 这似乎与最后一行有关server.R 因为这只是一个单词,所以我不清楚 'cat' 失败的原因是什么,即连接。
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")
)
)
))
很难说,因为我无法重现你的应用程序,但你应该试试:
output$out <- renderText({ans()})
或 output$out <- renderText(ans())
.
如果省略 ()
,您将访问反应本身,而不是它的值。有点像当您为函数键入 foo
而不是 foo()
时。
我正在构建一个闪亮的应用程序,它接受用户的文本输入,将最后两个词与三元组数据框进行比较,以预测最有可能出现的下一个词。在 server.R 下面,我试图输出的 triPred 函数的输出是一个单词。当我加载这个应用程序时,我在应用程序中键入一些文本后出现以下错误 - 'argument 1 (type 'closure') cannot be handled by 'cat' - 这似乎与最后一行有关server.R 因为这只是一个单词,所以我不清楚 'cat' 失败的原因是什么,即连接。
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")
)
)
))
很难说,因为我无法重现你的应用程序,但你应该试试:
output$out <- renderText({ans()})
或 output$out <- renderText(ans())
.
如果省略 ()
,您将访问反应本身,而不是它的值。有点像当您为函数键入 foo
而不是 foo()
时。