闪亮的服务器中的R脚本,导致多个错误

时间:2019-06-03 12:08:57

标签: shiny

我正在尝试构建一个闪亮的Twitter分析应用程序。

逻辑是,一旦输入搜索词,然后单击操作按钮,就可以完成工作。

但是,在这种情况下,未完成任何操作,而是显示一条错误消息。

有一个函数搜索推文,它返回带有1列标记为text的df,这是我尝试清洁和处理的列

ui <- fluidPage(

  fluidRow( 
    column( 4, titlePanel("Twitter Analytics")),
    column( 3),
    column( 4, 
            textInput("searchstring", 
                      label = "",
                      value = "")),
    column(1, 
           br(),
           actionButton("action", "go"))
  ),
  fluidRow(
    column( 12, tabsetPanel(
      tabPanel("one",
               fluidRow(
                 column(3 ),
                 column(9,  plotOutput("ttext"))
                 )
         ),    
    tabPanel("two"),
    tabPanel("three"), 
    tabPanel("DataTable",
             fluidRow(
               column(12, dataTableOutput("mysearch") 
               )
             )
           )
         )
       )
     )
   )

server <- function(input, output) {

  twitter <- eventReactive(input$action,{
    search_tweets( input$searchstring , n = 50, include_rts = FALSE)

  })

  output$mysearch  <- renderDataTable({
    twitter()
  }) 
  output$ttext <- renderUI({ 
    df <- twitter()
    df<- as.data.frame(df)
    df$text = tolower(df$text)
    # # Replace @UserName
    df$text <- gsub("@\\w+", "", df$text)
    # #remove punctuation
    df$text <- gsub("[[:punct:]]", "", df$text)
    # #remove links
    df$text <- gsub("http\\w+", "", df$text)
    # # Remove tabs
    df$text <- gsub("[ |\t]{2,}", "", df$text)
    # # Remove blank spaces at the beginning
    df$text <- gsub("^ ", "", df$text)
    # # Remove blank spaces at the end
    df$text <- gsub(" $", "", df$text)
    corpus <- iconv(df$text, to = "ASCII")
    corpus <- Corpus(VectorSource(corpus))
    corpus <- tm_map(corpus, removePunctuation)
    corpus <- tm_map(corpus, removeNumbers)
    cleanset <- tm_map(corpus, removeWords, stopwords('english'))
    cleanset <- tm_map(cleanset, stripWhitespace)
    tdm <- TermDocumentMatrix(cleanset)
    tdm <- as.matrix(tdm)
    w <- rowSums(tdm)
    w<- subset(w, w>=13)
    barplot(w, 
            main="Word Frequency in Sri Lanka Tweetset",
            las = 2,
            col = brewer.pal(n = n, name = "YlGnBu"))
  })
}

shinyApp(ui, server)

当我在rstudio和Shiny中运行代码时遇到这些错误,在rstudio中,它不会阻止我执行任何操作,尽管Shiny刚刚关闭,我们将不胜感激

Finished collecting tweets!
Warning in tm_map.SimpleCorpus(corpus, removePunctuation) :
  transformation drops documents
Warning in tm_map.SimpleCorpus(corpus, removeNumbers) :
  transformation drops documents
Warning in tm_map.SimpleCorpus(corpus, removeWords, stopwords("english")) :
  transformation drops documents
Warning in tm_map.SimpleCorpus(cleanset, stripWhitespace) :
  transformation drops documents
Warning: Error in <: comparison (3) is possible only for atomic and list types

0 个答案:

没有答案