首页 > 解决方案 > 无法将类型“闭包”强制为向量

问题描述

我正在开发一个闪亮的应用程序,但无法弄清楚为什么会出现此错误。错误消息说

警告:as.character 中的错误:无法将类型“闭包”强制转换为“字符”类型的向量 [没有可用的堆栈跟踪]

感谢帮助!下面是我的代码

用户界面

library(shiny)

suppressPackageStartupMessages(c(
    library(shinythemes),
    library(shiny)
))

# give the application a title and browser tab text
appTitle = (div(HTML("<center>Project</center>")))

# create tabs and panels
shinyUI(fluidPage(
    titlePanel(appTitle,browserText),
    theme = shinytheme("united"),
    sidebarLayout(
        sidebarPanel(
            h3("Overview"),
            p("This application will predict next words for you based on the word or phrase you enter.  
                   Please, note that only English is supported."),
            h3("Instructions"),
            tags$ul(
                tags$li("Enter a phrase in English, into the textbox 'Input'"), 
                tags$li("Click anywhere outside the textbox"), 
                tags$li("Your 'suggested next word' will appear below the textbox"),
                tags$li("Also Your given input will appear below the suggested next word")
            ),
        ),
        mainPanel(id="mainpanel",
                  textInput("text", "Input"),
                  h4("Suggested next word:"),
                  tags$span(style="color:red",
                            tags$strong(tags$h3(textOutput("nextWords")))),
                  h4("Your input:"),
                  tags$span(style="color:red",
                            tags$em(tags$h3(textOutput("inputWords")))), align="center"))
)
)

服务器.R


library(shiny)

suppressPackageStartupMessages(
    c(library(stringr), library(stylo), library(tm)
    ))

# include helper functions
source(".//predict.R")
quadgram <- readRDS(file = ".//quadgram.RData")
trigram <- readRDS(file = ".//trigram.RData")
bigram <- readRDS(file = ".//bigram.RData")


# word prediction service
shinyServer(function(input, output) {
    nextWord <- reactive({
        x <- input$text
        y <- callingClean(x)
        wCount <- length(y)
        nextWord <- getNextWord(wCount,y)})
    
    output$nextWords <- renderPrint(nextWord())
    output$inputWords <- renderText({input$text}, quoted = FALSE)
    
})

标签: rshiny

解决方案


推荐阅读