Thursday, April 28, 2016

Host shiny server in Ubuntu 14.04 LTS

I have installed shiny server on Ubuntu 14.04 LTS running under a VM. This post is a collection of commands that I had used for setup. Note that if you want to use shiny server on LAN than use Bridged Network Adapter.

On VM you can access shiny server via localhost:3838 and on remote machines you can use IP-address:3838 to open it. You can host your shiny app in /srv/shiny-server/ directory. You can go to /etc/shiny-server/shiny-server.conf to change default configurations like you can change port with listen <port number>; in server {} module.

$ sudo sh -c 'echo "deb http://cran.rstudio.com/bin/linux/ubuntu trusty/" >> /etc/apt/sources.list'

$ sudo gpg --keyserver keyserver.ubuntu.com --recv-key E084DAB9

$ sudo gpg -a --export E084DAB9 | sudo apt-key add -

$ sudo apt-get update

$ sudo apt-get -y install r-base

$ sudo su - -c "R -e \"install.packages(c('shiny','shinyjs','shinydashboard','shinythemes','devtools','rmarkdown'), repos = 'http://cran.rstudio.com/')\""

$ sudo apt-get install gdebi-core

$ sudo wget https://download3.rstudio.org/ubuntu-12.04/x86_64/shiny-server-1.4.2.786-amd64.deb

$ sudo gdebi shiny-server-1.4.2.786-amd64.deb

$ sudo start shiny-server

$ sudo status shiny-server

Source:

Tuesday, April 26, 2016

Generate word cloud in R

TEXT (.txt)

This working script was tested on R 3.2.5. Code is adapted from https://github.com/gimoya/theBioBucket-Archives/blob/master/R/txtmining_pdf.R. It reads a text file, processes it to remove unnecessary words and plots it.

Code:

library(tm)
library(wordcloud)
library(Rstem)

filetxt <- "C:\\Users\\310211146\\Documents\\Other\\May_Report.txt"

txt <- readLines(filetxt)
txt <- tolower(txt)
txt <- removeWords(txt, c("\\f", stopwords()))

corpus <- Corpus(VectorSource(txt))
corpus <- tm_map(corpus, removePunctuation)

tdm <- TermDocumentMatrix(corpus)

m <- as.matrix(tdm)

d <- data.frame(freq = sort(rowSums(m), decreasing = TRUE))
d$stem <- wordStem(row.names(d), language = "english")
d$word <- row.names(d)
d <- d[nchar(row.names(d)) < 20,]

agg_freq <- aggregate(freq ~ stem, data = d, sum)
agg_word <- aggregate(word ~ stem, data = d, function(x)
  x[1])

d <- cbind(freq = agg_freq[, 2], agg_word)
d <- d[order(d$freq, decreasing = T),]

wordcloud(d$word, d$freq)

Output:

Friday, April 22, 2016

Learn R with 5 Video Tutorials

If you are new to R or wants to enhance your basic skills in R and wondering where to get started provided there is lots of free material available online then you have come to right place. I have presented 5 video tutorials that is more than enough to get you started with R and will push you in direction of excelling R.

1. What is R and How to install it?


2. What are data types and variables in R?