Skip to content

Commit

Permalink
working on shiny apps
Browse files Browse the repository at this point in the history
  • Loading branch information
bcaffo committed Jan 15, 2014
1 parent 12479a4 commit 6e06bd2
Show file tree
Hide file tree
Showing 11 changed files with 401 additions and 396 deletions.
17 changes: 17 additions & 0 deletions 07_RegressionModels/scratch.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
title : Scratch work
subtitle :
author : Brian Caffo, Jeff Leek and Roger Peng
job : Johns Hopkins Bloomberg School of Public Health
logo : bloomberg_shield.png
framework : io2012 # {io2012, html5slides, shower, dzslides, ...}
highlighter : highlight.js # {highlight.js, prettify, highlight}
hitheme : tomorrow #
url:
lib: ../../libraries
assets: ../../assets
widgets : [mathjax] # {mathjax, quiz, bootstrap}
mode : selfcontained # {standalone, draft}
---

---
96 changes: 96 additions & 0 deletions 07_RegressionModels/scratch.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<!DOCTYPE html>
<html>
<head>
<title>Scratch work</title>
<meta charset="utf-8">
<meta name="description" content="Scratch work">
<meta name="author" content="Brian Caffo, Jeff Leek and Roger Peng">
<meta name="generator" content="slidify" />
<meta name="apple-mobile-web-app-capable" content="yes">
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<link rel="stylesheet" href="../../libraries/frameworks/io2012/css/default.css" media="all" >
<link rel="stylesheet" href="../../libraries/frameworks/io2012/phone.css"
media="only screen and (max-device-width: 480px)" >
<link rel="stylesheet" href="../../libraries/frameworks/io2012/css/slidify.css" >
<link rel="stylesheet" href="../../libraries/highlighters/highlight.js/css/tomorrow.css" />
<base target="_blank"> <!-- This amazingness opens all links in a new tab. -->
<script data-main="../../libraries/frameworks/io2012/js/slides"
src="../../libraries/frameworks/io2012/js/require-1.0.8.min.js">
</script>


</head>
<body style="opacity: 0">
<slides class="layout-widescreen">

<!-- LOGO SLIDE -->
<!-- END LOGO SLIDE -->


<!-- TITLE SLIDE -->
<!-- Should I move this to a Local Layout File? -->
<slide class="title-slide segue nobackground">
<aside class="gdbar">
<img src="../../assets/img/bloomberg_shield.png">
</aside>
<hgroup class="auto-fadein">
<h1>Scratch work</h1>
<h2></h2>
<p>Brian Caffo, Jeff Leek and Roger Peng<br/>Johns Hopkins Bloomberg School of Public Health</p>
</hgroup>
</slide>

<!-- SLIDES -->
<slide class="" id="slide-1" style="background:;">
<hgroup>

</hgroup>
<article>

</article>
<!-- Presenter Notes -->
</slide>

<slide class="" id="slide-2" style="background:;">
<hgroup>

</hgroup>
<article>

</article>
<!-- Presenter Notes -->
</slide>

<slide class="backdrop"></slide>
</slides>

<!--[if IE]>
<script
src="http://ajax.googleapis.com/ajax/libs/chrome-frame/1/CFInstall.min.js">
</script>
<script>CFInstall.check({mode: 'overlay'});</script>
<![endif]-->
</body>
<!-- Grab CDN jQuery, fall back to local if offline -->
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.min.js"></script>
<script>window.jQuery || document.write('<script src="../../libraries/widgets/quiz/js/jquery-1.7.min.js"><\/script>')</script>
<!-- Load Javascripts for Widgets -->
<!-- MathJax: Fall back to local if CDN offline but local image fonts are not supported (saves >100MB) -->
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {
inlineMath: [['$','$'], ['\\(','\\)']],
processEscapes: true
}
});
</script>
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/2.0-latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<!-- <script src="https://c328740.ssl.cf1.rackcdn.com/mathjax/2.0-latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script> -->
<script>window.MathJax || document.write('<script type="text/x-mathjax-config">MathJax.Hub.Config({"HTML-CSS":{imageFont:null}});<\/script><script src="../../libraries/widgets/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"><\/script>')
</script>
<!-- LOAD HIGHLIGHTER JS FILES -->
<script src="../../libraries/highlighters/highlight.js/highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<!-- DONE LOADING HIGHLIGHTER JS FILES -->
</html>
17 changes: 17 additions & 0 deletions 07_RegressionModels/scratch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
title : Scratch work
subtitle :
author : Brian Caffo, Jeff Leek and Roger Peng
job : Johns Hopkins Bloomberg School of Public Health
logo : bloomberg_shield.png
framework : io2012 # {io2012, html5slides, shower, dzslides, ...}
highlighter : highlight.js # {highlight.js, prettify, highlight}
hitheme : tomorrow #
url:
lib: ../../libraries
assets: ../../assets
widgets : [mathjax] # {mathjax, quiz, bootstrap}
mode : selfcontained # {standalone, draft}
---

---
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
214 changes: 111 additions & 103 deletions 09_DevelopingDataProducts/shiny/index.Rmd
Original file line number Diff line number Diff line change
@@ -1,103 +1,111 @@
---
title : Shiny
subtitle : Data Products
author : Brian Caffo, Jeff Leek, Roger Peng
job : Johns Hopkins Bloomberg School of Public Health
logo : bloomberg_shield.png
framework : io2012 # {io2012, html5slides, shower, dzslides, ...}
highlighter : highlight.js # {highlight.js, prettify, highlight}
hitheme : tomorrow #
url:
lib: ../../libraries
assets: ../../assets
widgets : [mathjax] # {mathjax, quiz, bootstrap}
mode : selfcontained # {standalone, draft}
---

## What is Shiny?

- Shiny is a platform for creating interactive R programs embeded into a web page.
- Suppose that you create a prediction algorith, with shiny you can *very easily* create web input form that calls R and thus your prediction algorithm and displays the results.
- Using Shiny, the time to create simple, yet powerful, web-based interactive data products in R is minimized.
- However, it lacks the flexibility of full featured (and more complex) solutions.
- Shiny is made by the fine folks at R Studio.

---
## Some mild prerequisites
- Shiny doesn't really require it, but as with all web programming, a little knowledge of html, css and js is very helpful
- html gives a web page structure and sectioning as well as markup instructions
- css gives the style
- js for interactivity
- There are too many tutorials online to count for getting basic proficiency in these topics to count.
- Shiny uses [bootstrap](http://getbootstrap.com/) (no relation to the statistics bootstrap) style, which (to me) seems to look nice and renders well on mobile platforms

---
## What else is out there?
- Full solutions requiring real knowledge of web client/server programming
- [OpenCPU](https://public.opencpu.org/) by Jerome Ooms, a really neat project providing an API to call

---
## Context
- You created a novel prediction algorithm to predict risk for developing
diabetes.
- You're hoping patients and caregivers will be able to enter their data and, if needed, take preventative measures.
- You want to create a web site so that users can input the relevant predictors and obtain their prediction.
- Your prediction algorithm (ok, so you're not going to be saving the world with this one)
- (link for a real prediction score)[http://www.ncbi.nlm.nih.gov/pubmed/12610029]
```{r}
diabetesRisk <- function(glucose){
runif(1)
}
```


---
## Getting started
- Great tutorial at
(http://rstudio.github.io/shiny/tutorial/)[http://rstudio.github.io/shiny/tutorial/]
- Basically, this lecture is walking through that tutorial offering some of our insights
- Note, some of the proposed interactive plotting uses of Shiny could be handled by the very simple `manipulate` function (rstudio manipulate)[http://www.rstudio.com/ide/docs/advanced/manipulate]
- Also, `rCharts` is will be covered in a different lecture.

```
install.packages("shiny")
```

```{r}
library(shiny)
```

---
## A Shiny project
- A shiny project contains two parts
- One named ui.R (for user interface) controls how it looks.
- One named server.R that controls what it does.

---
##
```
library(shiny)
shinyUI(pageWithSidebar(
headerPanel("Hello Shiny!"),
sidebarPanel(
sliderInput("obs",
"Number of observations:",
min = 1,
max = 1000,
value = 500)
),
mainPanel(
plotOutput("distPlot")
)
))
```

---
##







---
title : Shiny
subtitle : Data Products
author : Brian Caffo, Jeff Leek, Roger Peng
job : Johns Hopkins Bloomberg School of Public Health
logo : bloomberg_shield.png
framework : io2012 # {io2012, html5slides, shower, dzslides, ...}
highlighter : highlight.js # {highlight.js, prettify, highlight}
hitheme : tomorrow #
url:
# lib: ../../libraries
assets: ../../assets
widgets : [mathjax] # {mathjax, quiz, bootstrap}
mode : selfcontained # {standalone, draft}
---

## What is Shiny?

- Shiny is a platform for creating interactive R programs embeded into a web page.
- Suppose that you create a prediction algorith, with shiny you can *very easily* create web input form that calls R and thus your prediction algorithm and displays the results.
- Using Shiny, the time to create simple, yet powerful, web-based interactive data products in R is minimized.
- However, it lacks the flexibility of full featured (and more complex) solutions.
- Shiny is made by the fine folks at R Studio.

---
## Some mild prerequisites
- Shiny doesn't really require it, but as with all web programming, a little knowledge of html, css and js is very helpful
- html gives a web page structure and sectioning as well as markup instructions
- css gives the style
- js for interactivity
- There are too many tutorials online to count for getting basic proficiency in these topics to count.
- Shiny uses [bootstrap](http://getbootstrap.com/) (no relation to the statistics bootstrap) style, which (to me) seems to look nice and renders well on mobile platforms

---
## What else is out there?
- Full solutions requiring real knowledge of web client/server programming
- [OpenCPU](https://public.opencpu.org/) by Jerome Ooms, a really neat project providing an API to call

---
## Context
- You created a novel prediction algorithm to predict risk for developing
diabetes.
- You're hoping patients and caregivers will be able to enter their data and, if needed, take preventative measures.
- You want to create a web site so that users can input the relevant predictors and obtain their prediction.
- Your prediction algorithm (ok, so you're not going to be saving the world with this one)
- (link for a real prediction score)[http://www.ncbi.nlm.nih.gov/pubmed/12610029]
```{r}
diabetesRisk <- function(glucose){
runif(1)
}
```


---
## Getting started
- Make sure you have the latest release of R installed
- If on windows, make sure that you have Rtools installed
- `install.packages("shiny")`
- `libray(shiny)`
- Great tutorial at
[http://rstudio.github.io/shiny/tutorial/](http://rstudio.github.io/shiny/tutorial/)
- Basically, this lecture is walking through that tutorial offering some of our insights
- Note, some of the proposed interactive plotting uses of Shiny could be handled by the very simple `manipulate` function [rstudio manipulate](http://www.rstudio.com/ide/docs/advanced/manipulate)
- Also, `rCharts` is will be covered in a different lecture.

---
## A Shiny project
- A shiny project is a directory containing at least two parts
- One named ui.R (for user interface) controls how it looks.
- One named server.R that controls what it does.

---
## ui.R
```
library(shiny)
shinyUI(pageWithSidebar(
headerPanel("Data science FTW!"),
sidebarPanel(
h3('Sidebar text')
),
mainPanel(
h3('Main Panel text')
)
))
```

---
## server.r
```
library(shiny)
shinyServer(
function(input, output) {
}
)
```

---
## To run it
- In R, change to the directories with these files and type `runApp()`
- or put the path to the directory as an argument
- It should open an browser window with the app running

---
![simplestApp](fig/simplestApp.png "First Shiny app")







Loading

0 comments on commit 6e06bd2

Please sign in to comment.