不久前,我问了一个关于同一个Shiny应用程序的问题,尽管现在肯定已经变得更加有意义了,但我仍然遇到了一些障碍。该应用程序旨在抓取Twitter和Reddit,使每个词带回一个词云。 Twitter可以完美运行,但是Reddit会进行搜索和清理,但实际上不会创建词云。我很确定问题出在用户尚未搜索时将reddit数据集设置为“ NULL”,因为我以非发光形式使用了其余代码,并且工作正常。您能给予的任何帮助,我将不胜感激!
#Define server logic
server <- function(input, output, session) {
red_data <- reactiveValues(df = NULL)
# Define a reactive expression for the document term matrix
observeEvent(input$update,{
# reddit cleaning
red_data = get_reddit(search_terms="selection")
red_data=Corpus(VectorSource(red_data$comment))
red_data=tm_map(red_data,tolower)
red_data=tm_map(red_data, removeNumbers)
red_data=tm_map(red_data, removePunctuation)
red_data=tm_map(red_data, stripWhitespace)
red_data=tm_map(red_data,function(x)removeWords(x,stopwords()))
red_data=tm_map(red_data,PlainTextDocument)
red_data=tm_map(red_data, removeWords, c("like", "com", "www", "https", "http", "reddit", "just", "also","amp", "get","can", "will", "cobb", "county", "school","schools"))
red_data<-Corpus(VectorSource(red_data))
})
output$plot2 <- renderPlot({
# plot it
if(is.null(red_data)){
NULL
} else{
col=brewer.pal(6,"Set2")
wordcloud(red_data$comment, min.freq = 10, scale = c(5,0.5), rot.per = 0.25,
}
})
}