创建一个闪亮的wordcloud

时间:2017-03-08 13:34:21

标签: r matrix shiny text-analysis word-cloud

我正在尝试创建一个带有闪亮的wordcloud,其中云将根据selectinput进行更改。我无法在renderplot中使用在reactive()内创建的变量。我的脚本正在关注

library(shiny)
#UI
shinyUI(fluidPage(
 # Application title
 titlePanel("Word Clouds "),
 # Sidebar with a slider input for number of bins
 sidebarLayout(
   sidebarPanel(
     selectInput("var",
              "Choose Group:",
  choices= c("High","Low"),
  selected="Low")),

# Show a plot of the generated distribution
mainPanel(
  plotOutput("Plot1")))))


# Server 
# keeping dtm inside reactive function, bec it will change with every select input  

library(shiny)
library(slam)
library(tm)
library(RColorBrewer)
library(wordcloud)
data = read.csv("abc.csv")
data = tolower(data)


shinyServer(function(input, output) {
  data1 =reactive({
  sample_c=data[data$col1==input$var,]
  Corp <- Corpus(VectorSource(sample_c$desc_copy))
  dtm=TermDocumentMatrix(Corp, control=list(weighting=weightTfIdf))     
  tdm.spar=removeSparseTerms(dtm, sparse=0.9)  
  ddm= rollup(tdm.spar,2,na.rm=TRUE, FUN=sum) # using slam package bec of huge data 
  m <- as.matrix(ddm)
  v <- sort(rowSums(m),decreasing=TRUE)
  d <- data.frame(word = names(v),freq=v)
  list (d1=d)})

  wordcloud_rep <- repeatable(wordcloud)

  output$Plot1 <- renderPlot({
   data2=data1()$d1  
   set.seed(1234)
   wordcloud_rep(words = data2$word, freq = data2$freq, min.freq = 1,
          max.words=200, random.order=FALSE, rot.per=0.35, 
          colors=brewer.pal(8, "Dark2"))   }) })

我收到错误

  

无效的cex值

一次又一次。我将非常感谢每一个帮助

0 个答案:

没有答案