Generalize app serving

- Separate generic server code from app logic
- Refactor folder layout to put examples in separate folders
- Separate shared client assets from app-specific stuff
- Introduce friendly functions for interacting with framework from app logic
This commit is contained in:
Joe Cheng
2012-06-26 21:52:44 -07:00
parent 141c57ad1e
commit 6955573dd0
10 changed files with 153 additions and 67 deletions

15
examples/02_hash/app.R Normal file
View File

@@ -0,0 +1,15 @@
library(digest)
input <- Observable$new(function() {
str <- get.shiny.input('input1')
if (get.shiny.input('addnewline'))
str <- paste(str, "\n", sep='')
return(str)
})
define.shiny.output('md5_hash', function() {
digest(input$get.value(), algo='md5', serialize=F)
})
define.shiny.output('sha1_hash', function() {
digest(input$get.value(), algo='sha1', serialize=F)
})

View File

@@ -0,0 +1,26 @@
<html>
<head>
<script src="shared/jquery-1.7.2.js" type="text/javascript"></script>
<script src="shared/shiny.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="shared/shiny.css"/>
</head>
<body>
<h1>Example 2: Hash Calculation</h1>
<p>
<label>Input:</label><br />
<input name="input1" value="Hello World!"/>
<input type="checkbox" name="addnewline" checked="checked"/> Append newline
</p>
<p>
<label>MD5:</label><br />
<pre id="md5_hash" class="live-text"></pre>
</p>
<p>
<label>SHA-1:</label><br />
<pre id="sha1_hash" class="live-text"></pre>
</p>
</body>
</html>

View File

@@ -0,0 +1,24 @@
data <- Observable$new(function() {
# Choose a distribution function
dist <- switch(get.shiny.input('dist'),
norm = rnorm,
unif = runif,
lnorm = rlnorm,
exp = rexp,
rnorm)
# Generate n values from the distribution function
dist(max(1, get.shiny.input('n')))
})
define.shiny.plot('plot1', function() {
dist <- get.shiny.input('dist')
n <- get.shiny.input('n')
hist(data$get.value(),
main=paste('r', dist, '(', n, ')', sep=''))
}, width=600, height=300)
define.shiny.table('table1', function() {
data.frame(x=data$get.value())
})

View File

@@ -0,0 +1,30 @@
<html>
<head>
<script src="shared/jquery-1.7.2.js" type="text/javascript"></script>
<script src="shared/shiny.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="shared/shiny.css"/>
</head>
<body>
<h1>Example 3: Distributions</h1>
<p>
<label>Distribution type:</label><br />
<select name="dist">
<option value="norm">Normal</option>
<option value="unif">Uniform</option>
<option value="lnorm">Log-normal</option>
<option value="exp">Exponential</option>
</select>
</p>
<p>
<label>Number of observations:</label><br />
<input type="numeric" name="n" value="500" />
</p>
<div id="plot1" class="live-plot"></div>
<div id="table1" class="live-html"></div>
</body>
</html>