我的闪亮R项目无法正常工作

时间:2018-06-24 15:04:35

标签: r shiny

我的Shiny R项目在一个月前运行完美(没有任何错误),但根本无法正常工作。我没有更改任何代码,但它给了我很多错误。 谁能帮我 ???我还在朋友的笔记本电脑上尝试过相同的代码,但仍然无法正常工作。

Ui.R

library(shiny)
library(plotly)
library(ggplot2)
library(sentimentr)
library(syuzhet)
library(stringr)


shinyUI(fluidPage(
  titlePanel("Analysis of online food ordering websites"),
  titlePanel(""),
  tags$head(
    tags$style(HTML("body {
                    background-color: white;
                    color: #6B1413;}"))),

  navbarPage("My Application",
             tabPanel("Home",

                      mainPanel(
                       img(src="6.png",align="right",height = 400, width = 600)

                      )),

             navbarMenu("Sitewise Comparision",
                        tabPanel(" "),
                        tabPanel("Zomatos vs Foodpanda",
                                 sidebarPanel(
                                   tabsetPanel(
                                     tabPanel("Foodpanda" , textInput('t1', "write your review"),            
                                              actionButton("Action1","Submit"),textOutput("o1")),
                                     tabPanel("zomato" , textInput('t2', "write your review"),            
                                              actionButton("Action2","Submit"),textOutput("o2")))),
                                 mainPanel(
                                   plotlyOutput(outputId = "first" , width = "60%", height = "2%"),
                                   status = "warning"),
                                 tabsetPanel(
                                   tabPanel("Foodpanda",DT::dataTableOutput("foodpandaData")),
                                   tabPanel("Zomato",value="a",DT::dataTableOutput("zomatoData")
                                   ))
                        ),


Server.R               

library(shiny)
library(sentimentr)
library(stringr)
library(ggplot2)
library(tm)
library(corrplot)
library(plotly)
library(SnowballC)
options(shiny.sanitize.errors = FALSE)

server <- function(input,output){
  output$first<- renderPlotly({
    src <- DirSource("./Data/Site comparision")
    docs <- Corpus(src)
    docs <- tm_map(docs, removePunctuation)
    docs <- tm_map(docs,content_transformer(tolower))
    docs <- tm_map(docs, removeNumbers)
    docs <- tm_map(docs, removeWords,stopwords("english"))
    docs <- tm_map(docs, stripWhitespace)
    docs <- tm_map(docs, stemDocument)
    writeCorpus(docs, path="./Data")
    filePath <- "./Data/FoodPanda.csv.txt"
    texts<- readLines(filePath)
    opinion.lexicon.pos <- scan('./Data/positive-word.txt', what='character', comment.char = ';')
    opinion.lexicon.neg <- scan('./Data/negative-word.txt', what='character', comment.char = ';')
    jj <- str_split(texts, pattern="\\s+")
    a <- lapply(jj,function(x){sum(!is.na(match(x,opinion.lexicon.pos)))})
    b <- lapply(jj,function(x){sum(!is.na(match(x,opinion.lexicon.neg)))})
    filePath <- "./Data/zomato.csv.txt"
    texts2<- readLines(filePath)
    jj <- str_split(texts2, pattern="\\s+")
    e <- lapply(jj,function(x){sum(!is.na(match(x,opinion.lexicon.pos)))})
    f <- lapply(jj,function(x){sum(!is.na(match(x,opinion.lexicon.neg)))})
    x <- c('FoodPanda','Zomato')
    y1 <- c(a,e)
    y2 <- c(b,f)
    data <- data.frame(x,y1,y2)
    first <- plot_ly(data, x = ~x, y = ~y1, type = 'bar', name = 'Positive', marker = list(color = 'rgb(49,130,189)')) %>%
      add_trace(y = ~y2, name = 'negative', marker = list(color = 'rgb(204,204,204)')) %>%
      layout(title = "Site Comparision", xaxis = list(title = "Terms"),yaxis = list(title = "Frequency"),
             margin = list(b = 100),barmode = 'group')
    first$elementId <- NULL
    first })}

这是我的两个文件,一个是Ui.r,另一个是server.R

0 个答案:

没有答案