我正在尝试加载一个闪亮的应用程序,以预测用户输入后的下一个最可能出现的单词。它在本地工作正常,但是当我将其发布到闪亮的位置时,我在日志中收到错误消息和以下消息: PredictWord3中的错误:找不到对象“ x”。
我尝试用起始值定义x,但没有用
我的用户界面
library(shiny)
# Define UI for application
shinyUI(fluidPage(
# Application title
titlePanel("Predicting next word"),
# Sidebar
sidebarLayout(
sidebarPanel(
textInput("Word",
"Enter your word or phrase"
)
),
# Show the word
mainPanel(
textOutput("Word1")
)
)
))
我的服务器
library(shiny)
library(quanteda)
library(dplyr)
library(reticulate)
use_python("python3.5", require = FALSE)
x<-a
source("PredictWord3.R")
readRDS(("freq1.rds"))
readRDS(("freq2.rds"))
readRDS(("freq3.rds"))
readRDS(("freq4.rds"))
# Define server logic required to draw a histogram
shinyServer(function(input, output) {
z<-reactive({PredictWord3(input$Word)})
output$Word1<-renderText({z()
})
})
我的PredictWord3功能
PredictWord3<-function(sentence){
#cleaning the sentence as the training data
sentence<-tokens(sentence, "word", remove_numbers=TRUE,
remove_punct=TRUE, remove_symbols=TRUE, remove_separators=TRUE,
remove_twitter=TRUE, remove_hyphens=TRUE, remove_url = TRUE, ngrams=1,
concatenator=" ")
#Counting the words
words<-unlist(sentence, " ")
wordcount<-length(words)
#Finding the most probable next word if there are three or more words
if (wordcount>2){
words<-tail(words, n=3)
a<-filter(freq4, freq4[,1]==words[1] & freq4[,2]==words[2] & freq4[,3]==words[3])
x<-a[1,4]
}
#Finding the most probable next word if there are two words
if (wordcount==2 | is.na(x)){
words<-tail(words, n=2)
a<-filter(freq3, freq3[,1]==words[1] & freq3[,2]==words[2])
x<-a[1,3]
}
#Finding the most probable next word if there is only one word
if ((sentence!=""&wordcount==1) | is.na(x)){
words<-tail(words, n=1)
a<-filter(freq2, freq2[,1]==words[1])
x<-a[1,2]
}
#Finding the most probable next word if there is no word
if (sentence==""){
x<-names(freq1[1])
}
x
}
有人知道为什么吗?