입력 된 텍스트의 다음 단어를 예측하기 위해 R의 Shiny 앱을 연구 중입니다. 나는 응용 프로그램을 실행할 때마다 나는이 오류를 http://127.0.0.1:5714 경고에오류 : 유형 '환경'을 '문자'유형의 벡터로 강요 할 수 없습니다.
듣기가 나타납니다 오류 as.character에 :
유형 '문자'
스택 추적의 벡터에 유형 '환경'을 강요 할 수 없습니다 (안쪽 첫번째) : 1 : runApp은
오류 : 형식 '문자'
의 벡터에 유형 '환경'을 강요 할 수없는 내가 시도 모든 것을 내가 할 수있는 '이 t은
suppressWarnings(library(shiny))
shinyUI(fluidPage(
# Application title
navbarPage("Coursera Word Predection Final Project",
tabPanel("Home"),
navbarMenu("Method",
tabPanel("Description", p("This app uses a ngram backoff
model to predict the next word in a sentence."))
)),
# Sidebar layout
sidebarLayout(
sidebarPanel(
textInput("sentence", "Continue the sentence here below", value = "this
is a result of the"),
sliderInput("obs", "maximum predictions:",
min = 0, max = 30, value = 10
)
),
mainPanel(
h4("Sentence"),
verbatimTextOutput("text"),
h4("Prediction"),
verbatimTextOutput("prediction")
)
)
)
)
pred_words <- function(sentence, n = 10){
sentence <- removeNumbers(sentence)
sentence <- removePunctuation(sentence)
sentence <- tolower(sentence)
words <- unlist(strsplit(sentence, split = " "))
words <- tail(words, 5)
word1 <- words[1];word2 <- words[2];word3 <- words[3];word4 <-
words[4];word5 <- words[5];
datasub <- data.table()
if (nrow(datasub)==0 & !is.na(word5)) {
if(nrow(datasub) == 0) datasub <- subset(ngram6, w1==word1 & w2==word2 &
w3==word3 & w4==word4 & w5==word5)
if(nrow(datasub) == 0) datasub <- subset(ngram5, w1==word2 & w2==word3 &
w3==word4 & w4==word5)
if(nrow(datasub) == 0) datasub <- subset(ngram4, w1==word3 & w2==word4 &
w3==word5)
if(nrow(datasub) == 0) datasub <- subset(ngram3, w1==word4 & w2==word5)
if(nrow(datasub) == 0) datasub <- subset(ngram2, w1==word5)
}
if (nrow(datasub)==0 & !is.na(word4)) {
if(nrow(datasub) == 0) datasub <- subset(ngram5, w1==word1 & w2==word2 &
w3==word3 & w4==word4)
if(nrow(datasub) == 0) datasub <- subset(ngram4, w1==word2 & w2==word3 &
w3==word4)
if(nrow(datasub) == 0) datasub <- subset(ngram3, w1==word3 & w2==word4)
if(nrow(datasub) == 0) datasub <- subset(ngram2, w1==word4)
}
if (nrow(datasub)==0 & !is.na(word3)) {
if(nrow(datasub) == 0) datasub <- subset(ngram4, w1==word1 & w2==word2 &
w3==word3)
if(nrow(datasub) == 0) datasub <- subset(ngram3, w1==word2 & w2==word3)
if(nrow(datasub) == 0) datasub <- subset(ngram2, w1==word3)
}
if (nrow(datasub)==0 & !is.na(word2)) {
if(nrow(datasub) == 0) datasub <- subset(ngram3, w1==word1 & w2==word2)
if(nrow(datasub) == 0) datasub <- subset(ngram2, w1==word2)
}
if (nrow(datasub)==0 & !is.na(word1)) {
if(nrow(datasub) == 0) datasub <- subset(ngram2, w1==word1)
if(nrow(datasub) == 0) datasub <- head(ngram1)
}
if(nrow(datasub) > 0){
}
}
# Define server logic for the Word Prediction application
shinyServer(function(input, output) {
reactive({
pred_words(input$sentence, input$obs);
})
output$prediction <- renderPrint({
ds <- data_prediction()
if(nrow(ds)>0) {
head(subset(ds, freq==max(ds$freq))[,ncol(ds)-1],3)
cat(
paste(head(ds[,ncol(ds)-1]), collapse=', ')
)
}
})
})
# Run the application
shinyApp(ui = shinyUI, server = shinyServer)
정말 고마워. 이제 새로운 오류를 수정해야합니다. 나는 진심으로 감사한다. –