Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(shiny)
- library(tm)
- library(SnowballC)
- library(wordcloud)
- library(RColorBrewer)
- library(pdftools)
- library(DT)
- library(stringr)
- server <- function(input, output) {
- output$plot <- renderPlot({
- file1 <- input$file1
- file2 <- input$file2
- if (is.null(file1) && is.null(file2))
- return(NULL)
- if (!is.null(file1)) {
- in2 <- pdf_text(file1$datapath)
- }
- if (!is.null(file2)) {
- in2 <- readLines(file2$datapath)
- }
- docs <- Corpus(VectorSource(in2))
- toSpace <-
- content_transformer(function (x , pattern)
- gsub(pattern, " ",
- x))
- docs <- tm_map(docs, toSpace, "/")
- docs <- tm_map(docs, toSpace, "@")
- docs <- tm_map(docs, toSpace, "\\|")
- docs <- tm_map(docs, content_transformer(tolower))
- docs <- tm_map(docs, removeNumbers)
- docs <- tm_map(docs, removeWords, stopwords("dutch"))
- docs <- tm_map(docs, removeWords, stopwords("english"))
- docs <- tm_map(docs, removePunctuation)
- docs <- tm_map(docs, stripWhitespace)
- dtm <- TermDocumentMatrix(docs)
- m <- as.matrix(dtm)
- v <- sort(rowSums(m), decreasing = TRUE)
- d <- data.frame(word = names(v), freq = v)
- wordcloud_rep <- repeatable(wordcloud)
- wordcloud_rep(
- words = d$word,
- freq = d$freq,
- min.freq = input$freq,
- scale = c(2, 0.5),
- max.words = input$max,
- random.order = FALSE,
- rot.per = 0.35,
- colors = brewer.pal(8, "Dark2")
- )
- })
- output$table <- renderDataTable({
- file1 <- input$file1
- file2 <- input$file2
- if (is.null(file1) &&
- is.null(file2))
- return(NULL)
- if (!is.null(file1)) {
- in2 <- pdf_text(file1$datapath)
- }
- if (!is.null(file2)) {
- in2 <- readLines(file2$datapath)
- }
- docs <- Corpus(VectorSource(in2))
- toSpace <-
- content_transformer(function (x , pattern)
- gsub(pattern, " ",
- x))
- docs <- tm_map(docs, toSpace, "/")
- docs <- tm_map(docs, toSpace, "@")
- docs <- tm_map(docs, toSpace, "\\|")
- docs <- tm_map(docs, content_transformer(tolower))
- docs <- tm_map(docs, removeNumbers)
- docs <- tm_map(docs, removeWords, stopwords("dutch"))
- docs <- tm_map(docs, removeWords, stopwords("english"))
- docs <- tm_map(docs, removePunctuation)
- docs <- tm_map(docs, stripWhitespace)
- dtm <-
- TermDocumentMatrix(docs)
- m <- as.matrix(dtm)
- v <- sort(rowSums(m), decreasing = TRUE)
- as.data.frame(findAssocs(dtm, terms = input$v, corlimit = 0.3))
- })
- output$sent <- renderText({
- file1 <- input$file1
- file2 <- input$file2
- neg <- input$neg
- pos <- input$pos
- if (is.null(file1) && is.null(file2))
- return(NULL)
- if (!is.null(file1)){
- in2 <- pdf_text(file1$datapath)
- }
- if (!is.null(file2)){
- in2 <- readLines(file2$datapath)
- }
- if (!is.null(neg)) {
- neg <- readLines(neg$datapath)
- }
- if (!is.null(pos)) {
- pos <- readLines(pos$datapath)
- }
- text <- in2
- text <- str_split(text, pattern="\\s+")
- text <- unlist(text)
- pos.sum <- sum(!is.na(match(text,pos)))
- neg.sum <- sum(!is.na(match(text,neg)))
- negposr <- pos.sum/neg.sum
- print(negposr)
- })
- output$`2` <- renderDataTable({
- file1 <- input$file1
- file2 <- input$file2
- if (is.null(file1) &&
- is.null(file2))
- return(NULL)
- if (!is.null(file1)) {
- in2 <- pdf_text(file1$datapath)
- }
- if (!is.null(file2)) {
- in2 <- readLines(file2$datapath)
- }
- text <- in2
- docs <- Corpus(VectorSource(text))
- toSpace <-
- content_transformer(function (x , pattern)
- gsub(pattern, " ",
- x))
- text <-
- tm_map(docs, toSpace, "/")
- text <-
- tm_map(text, toSpace, "@")
- text <-
- tm_map(text, toSpace, "\\|")
- text <-
- tm_map(text, content_transformer(tolower))
- text <-
- tm_map(text, removeNumbers)
- text <-
- tm_map(text, removeWords, stopwords("dutch"))
- text <-
- tm_map(text, removeWords, stopwords("english"))
- text <-
- tm_map(text, removePunctuation)
- text <-
- tm_map(text, stripWhitespace)
- dtm <-
- TermDocumentMatrix(text)
- m <- as.matrix(dtm)
- v <- sort(rowSums(m), decreasing = TRUE)
- d <- data.frame(word = names(v),freq=v)
- head(d, 10)
- })
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement