A light-hearted bonus problem from my recent STAT 502 (Intro to Stat Inference for non-biostat majors) final exam. The standard problem:
followed by the bonus problem:
This link provides step by step instructions for setting up RStudio Server and Shiny on a Digital Ocean Ubuntu droplet: Dean Attali’s Blog Entry
It is very important to note that if one follows Step 9: Make pretty URLs for RStudio Server and Shiny Server, that one also follows these additional steps (from Dean Attali’s blog):
Bonus for advanced users: The above setup should be just fine for most users, but I did notice a few small issues with RStudio that seem to be fixed by allowing nginx to proxy WebSockets. For example, I noticed that when using the
ggvispackage in my RStudio, tooltips were not working. The fix is to add the following three lines inside the
location /rstudio/settings (keep the
proxy_passline and just add these three, and remember you have to restart nginx after changing the settings):
proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade";
If you’re hosting a Shiny Server, add these 3 lines after the
location /shiny/as well.
If those steps are not taken, then one will not be able to execute shiny apps from RStudio server (i.e., the app will start but the window will “gray” out). Complications may also appear with the R shiny server. However, allowing nginx to proxy Websockets remedies the problems.
Overview: These materials are for our November 11 Biostatistics, Genetics, and Genomics meeting. They constitute some notable highlights from a series of talks given by Dr. Martin Morgan as part of his Intermediate R Software Development short course. The image captures and example code below were prepared primarily by Mr. Ziqiang Chen, based upon the materials provided by Dr. Morgan in his course.
Setting up a GitHub account: https://github.com/ . Create a new project called ‘Knees’.
Create a new library in Rstudio:
Enable Git version control in Rstudio and connect to GitHub:
The Stick Person Code that we will use for our example library:
Add this function and two others to our R library:
Make sure to make some modfications for the ‘Knees’ package!
Document and Install and the Package:
Commit the changes locally:
Push the changes:
Run the code on the command line:
Now, setup the infrastructure for the RShiny App by creating a inst/sticky directory and adding these files:
Install the library and Run the Shiny App!
If you wish to skip all of the above, and just load Ziqiang’s version of the library:
library(devtools) install_github("ziqiangc/Knees") library(Knees) sticky()
Some Shiny RStudio Video tutorials (there are many to be found – thanks to Ziqiang Chen, for the links)
1. A (official) RStudio tutorial: http://shiny.rstudio.com/tutorial/
2. A comprehensive playlist of shiny tutorials: https://www.youtube.com/watch?v=_0ORRJqctHE&list=PL6wLL_RojB5xNOhe2OTSd-DPkMLVY9DfB
Some useful links provided to me by Ziqiang Chen:
1. The basic for dplyr and pipes, R markdown work through (GREAT): http://seananderson.ca/2014/09/13/dplyr-intro.html
3. %.% operator: https://martinsbioblogg.wordpress.com/2014/03/27/more-fun-with-and/
4. The vignette of magrittr (illustrative examples): https://cran.r-project.org/web/packages/magrittr/vignettes/magrittr.html
1. Basic, short walk through video about the pipe operator: https://www.youtube.com/watch?v=4fHNlUagm4g
2. A short tutorial about dplyr: https://www.youtube.com/watch?v=VnjujO8z4OI
3. A little longer tutorial about dplyr: https://www.youtube.com/watch?v=jWjqLW-u3hc
4. One hour presentation “Pipelines for Data Analysis” by Hadley Wickham: https://www.youtube.com/watch?v=40tyOFMZUSM
The origin of the name for the magrittr R library:
Paintings by Rene Magritte
This bit of R code will allow for the creation of a word cloud associated with the abstracts obtained via the pubmed search of a given search string.
Installation of Required Packages
# Install these packages if they are not currently installed if(!require('RWordPress')) install.packages('dev.tools') if(!require('wordcloud')) install.packages('wordcloud') if(!require('tm')) install.packages('tm') if(!require('RISmed')) install.packages('RISmed')
Install my simple PubMedWordCloud library from GitHub
if(!require('devtools')) install.packages('devtools') devtools:::install_github("dpgaile/PubMedWordCloud") library(PubMedWordCloud)
Creating a Word Cloud
Now, creating an word cloud for a pubmed search term is as easy as executing the following command:
PubMedWordCloud(SearchTerm="Dan Gaile OR Daniel Gaile", min.freq=3, max.words=250)