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)
})
})
})
error
message