1
所以我的闪亮的应用程序应该把一些文本作为输入,然后给出一个单词文本作为输出。但显然我得到错误 - “参数不是一个字符向量”。这是我的代码:r shiny的textAreaInput返回什么类型?
app.R
library(shiny)
server <- function(input, output) {
text1 <- eventReactive(input$actionButton,{
getPrediction(input$caption)
})
output$text1 <- renderUI({
text1()
})
}
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
textAreaInput(inputId="caption", label="Put your text here", width="100%", height="400px", value="", placeholder = "Placeholder"),
actionButton("actionButton", label = "Submit")
),
mainPanel(
h3("Name"),
textOutput("text1")
)
)
)
shinyApp(ui = ui, server = server)
helper.R
library(doMC)
registerDoMC(cores=detectCores())
getPrediction <- function(ptest){
corpus <- Corpus(VectorSource(ptest))
corpus.clean <- corpus %>%
tm_map(content_transformer(tolower)) %>%
tm_map(removePunctuation) %>%
tm_map(removeNumbers) %>%
tm_map(removeWords, stopwords(kind="en")) %>%
tm_map(stripWhitespace)
corpus.clean.test <- corpus.clean
fivefreq <- findFreqTerms(dtm.train, 5)
dtm.test.nb <- DocumentTermMatrix(corpus.clean.test, control=list(dictionary = fivefreq))
convert_count <- function(x) {
y <- ifelse(x > 0, 1,0)
y <- factor(y, levels=c(0,1), labels=c("No", "Yes"))
y
}
testNB <- apply(dtm.test.nb, 2, convert_count)
pred <- predict(classifier, newdata=testNB)
pred
}
我能做些什么,以打印出预测的输出?
它返回一个字符串。正如你可以用打印语句确定的那样。我认为正常工作,你认为这是错误来自哪里? –
我试图运行它,但我没有看到你定义'dtm.train'的地方,它正在死亡那里形成我。 –
哦,对了,我删除了。现在我得到一个新的错误:$运算符对原子向量无效。在这一点上,我真的不知道。我也第一次使用闪亮。这是整个代码:http://www.r-fiddle.org/#/fiddle?id=uq2FrPgE&version=2 你可以运行它吗?谢谢你的帮助。 – 0x1