0

I am trying to make bigram wordcloud in R Shiny. But its throwing error. Please find below my code for server.R and suggest where am I going wrong. I am able to make single word cloud but not bigram or trigram.

shinyServer(function(input, output) {

    wc_data = reactive({

input$update

isolate({

  withProgress({
    setProgress(message = "Processing Corpus...")
    wc_file = input$wc
    if(!is.null(wc_file)){
      wc_text = readLines(wc_file$datapath)
    }
    else
    {
      wc_text = "A wordcloud is an image made of words that together resemble a cloudy shape."
    }
    wc_corpus = Corpus(VectorSource(wc_text))
    wc_corpus_clean = tm_map(wc_corpus,tolower)
    wc_corpus_clean = tm_map(wc_corpus_clean, removePunctuation)
    wc_corpus_clean = tm_map(wc_corpus_clean, removeNumbers)
    wc_corpus_clean = tm_map(wc_corpus_clean, removeWords, stopwords("English"))
    wc_corpus_clean = tm_map(wc_corpus_clean, removeWords, c("since", "for", "this", "like", "that", "our", "united states", "will", "america", "s", "ve", "'"))
    wc_corpus_clean = tm_map(wc_corpus_clean, stripWhitespace)

    bigrams = textcnt(wc_corpus_clean, n = 2, method = "string")
    bigrams = bigrams[order(bigrams, decreasing = TRUE)]
    test_data = data.frame(bigrams = names(bigrams), freq = bigrams)
      })
    })
 })

  wordcloud_rep = repeatable(wordcloud)

  output$wcplot = renderPlot({
    withProgress({
      setProgress(message = "Creating WordCloud....")
      wc_corpus_clean = wc_data()
      wordcloud(wc_corpus_clean, min.freq = 5, scale = c(2,0.3), max.words  = 200, colors = brewer.pal(8,"Dark2"),rot.per = 0.45,random.order = FALSE)
   })
  })

})
2
  • 1
    Please include the error message
    – akrun
    Commented Jan 9, 2019 at 11:23
  • Please find below the error comment. Error: no applicable method for 'TermDocumentMatrix' applied to an object of class "data.frame"
    – Payal
    Commented Jan 10, 2019 at 4:59

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.