gpt4 book ai didi

r - Shiny 的应用程序因 "argument 1 (type ' 关闭而失败')无法由 'cat' 处理“- 这是什么意思?

转载 作者:行者123 更新时间:2023-12-02 17:01:05 26 4
gpt4 key购买 nike

我正在构建一个 Shiny 的应用程序,它接受用户的文本输入,将最后两个单词与三元组数据帧进行比较,以预测最有可能的下一个单词。在 server.R 中,我试图输出的 triPred 函数的输出下面是一个单词。当我加载此应用程序时,在应用程序中输入一些文本后出现以下错误 - 'argument 1(类型'closure')无法由'cat'处理 - 这似乎与 server.R 中的最后一行相关这只是一个词,我不清楚“cat”(即连接)失败的原因。

服务器.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()) .

如果省略() ,您访问的是 react 性本身,而不是它的值。有点像当你输入foo时而不是foo()对于一个函数。

关于r - Shiny 的应用程序因 "argument 1 (type ' 关闭而失败')无法由 'cat' 处理“- 这是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36522095/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com