R闪亮显示Wordcloud不显示

时间:2018-03-27 09:40:58

标签: r shiny

我使用以下代码在R shiny

中显示wordcloud
  library(shiny)
  library(shinydashboard)
  library(shinyjs)
  library(slam)
  library(tm)
  library(RColorBrewer)
  library(wordcloud)
  library(readxl)
  data <- read_excel("C:/Users/user/Desktop/AAA.xlsx")
  require(tm)
  text<-data$EmailSubject
  mycorpus<-Corpus(VectorSource(text))
  mycorpus<-tm_map(mycorpus, tolower)
  mycorpus<-tm_map(mycorpus, removeNumbers)
  mycorpus<-tm_map(mycorpus, removeWords, c(stopwords("english"))
  Encoding(text) <- "UTF-8"
  dtm<-TermDocumentMatrix(mycorpus)
  m<-as.matrix(dtm)
  v <- sort(rowSums(m),decreasing=TRUE)
  d <- data.frame(word = names(v),freq=v)
  list(d1=d)
   WC<-as.character(d$word)
   data<-data.frame(data)


    d<- word    freq
          save  42
         earth  14
         life   14
         aug    12
        name    11
        wate    11
       group    10
       email    9
      ignore    6
      please    6




    ui<- fluidPage(
    textInput("e-mail Subject", label = "Subject Line",placeholder = 
     "'"),actionButton("do", "Click Me"),
    numericInput("Audience Size", label = "Target Audience Size", value = 
    c(10000000)),
    dateInput("Date",label = "Date of Campaign"),
    mainPanel(plotOutput("Plot1")))





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


         shinyApp(ui, server)

输出页面显示输入面板和输出框,但图表不可见。我不确定我的错误在哪里。输出图应该是可见的。我请求别人帮忙

1 个答案:

答案 0 :(得分:0)

以下示例可以解决问题

library(shiny)
library(shinydashboard)
library(RColorBrewer)
library(wordcloud)
library(readxl)
d <- data.frame(c('save','earth'),c(42,14))
colnames(d) <- c('words','freq')
ui<- fluidPage(
textInput("e-mail Subject", label = "Subject Line",placeholder =   "'"),
actionButton("do", "Click Me"),
numericInput("Audience Size", label = "Target Audience Size", 
value =                   c(10000000)),
dateInput("Date",label = "Date of Campaign"),
mainPanel(plotOutput("Plot1")))

server<-function(input, output, session) {
output$Plot1 <- renderPlot({
set.seed(1234)
wordcloud(words = d$word, freq = d$freq, min.freq = 1,
                    max.words=200, random.order=FALSE, rot.per=0.35, 
                    colors=brewer.pal(8, "Dark2"))   })
}