2016-04-09 1 views
2

私は、ユーザのテキスト入力を受け取り、最も近い次の単語を予測するために、最後の2つの単語をトリグラムのデータフレームと比較するShinyアプリケーションを構築しています。 server.R以下のtriPred関数の出力の下に私はouptutしようとしている1つの単語です。このアプリケーションを読み込むと、アプリケーションにテキストを入力した後、次のエラーが表示されます - 引数1(type 'closure')は 'cat'で処理できません - server.Rの最終行に関連しているようですこれはちょうど1つの単語です、私は「cat」、つまり連結して何が失敗しているのか不明です。「引数1(タイプ 'クロージャー')は 'cat'で処理できません」というシャイニーアプリは失敗しました」 - これはどういう意味ですか?

server.R

library(stringr) 

shinyServer(function(input, output) { 

    triSplit <- function(input) { 
      el <- unlist(str_split(input," ")) 
      bigram <- paste(el[length(el)-1],el[length(el)]) 
      return(bigram) 
    } 

    triPred <- function(input) { 
      ## pulls out end words that match the input bigram 
      temp_wf_T <- wf_T[wf_T$start == triSplit(input),] 
      ##Picks one of the best options at random based on count 
      ans <- sample(temp_wf_T$end[temp_wf_T$count == max(temp_wf_T$count)],1) 
      return(ans) } 

    ##Read in a dataframe of bigrams, their possible completions, and counts of occurence 
    wf_T<-readRDS("C:/Users/LTM/DataScienceCertificateCapstone/ShinyTest/data/tdm.rds") 
    ##Runs the triPred function to guess the next most likely word 
    ans <- reactive(triPred(input$sent)) 
    ##generates an output variable to display 
    output$out <- renderText({ans}) 
    }) 

ui.R

library(shiny) 

shinyUI(fluidPage(
    titlePanel(h1("My Shiny App", align = "center")), 
    sidebarLayout(
      sidebarPanel(helpText("Please enter a sentence you would like me to complete"), 
      textInput("sent", label = "sentence")), 
      ########## 
      mainPanel(h1("Best Guess"), 
      br(), 
      textOutput("out") 
      ) 
    ) 
)) 

答えて

4

それは私があなたのアプリケーションを再現することはできませんので、伝えるのは難しいですが、あなたが試してみてください:

output$out <- renderText({ans()})か、単にoutput$out <- renderText(ans())

()を省略すると、その値ではなくリアクティブ自体にアクセスします。機能のためにfoo()の代わりにfooと入力すると少し似ています。

+0

これはエラーを修正するようです。そして、シャイニーと仕事をするための参考になる学習例です。有難うございます。 –

+0

ようこそ。 –

関連する問題