r - 为什么找不到对象“x”
问题描述
我正在尝试加载一个闪亮的应用程序来预测用户输入后下一个最可能的单词。它在本地运行良好,但是当我在闪亮时发布它时,我在日志中收到错误和以下消息: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
}
有谁知道为什么?
解决方案
推荐阅读
- android - 每 3 个字符之间的间距
- session - MySQL 8 禁用当前会话的查询缓存
- laravel - 如何将搜索栏中的值与laravel中数据库中的值进行比较
- sqlite - JavaFX删除tableview和sqlite中的数据行
- python - 使用 Pdftron 库
- python - Python多处理,将列表中的一项和完整列表作为参数解析到进程中
- c# - Unity - 如何将精灵组合成一个
- express - 如何在不使用 .htaccess 的情况下创建 404 页面
- postgresql - 将一行的列复制到条件的另一行,然后将其删除
- excel - 附加函数 addEventListener