HTML_ui

HTML_ui
shiny를 이용하면, 기본적인 html을 생성해 주지만, html을 직접 생성해서 사용할 수 있다.

기본 파일은 www/index.html로 지정
server.R(HTML_ui)
library(shiny)
shinyServer(function(input, output){
data<-reactive({
dist<-switch(input$dist, norm=rnorm, unif=runif, lnorm=rlnorm, exp=rexp, rnorm)
dist(input$n)
})
output$plot<-renderPlot({
dist<-input$dist
n<-input$n
hist(data(), main=paste("r", dist, "(", n, ")", sep=''))
})
output$summary<-renderPrint({
summary(data())
})
output$table<-renderTable({
data.frame(x=data())
})
})
index.html(HTML_ui)
<html>
<head>
<script src="shared/jquery.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>HTML UI</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="number" name="n" value="500" min="1" max="1000" />
</p>
<pre id="summary" class="shiny-text-output"></pre>
<div id="plot" class="shiny-plot-output" type="width: 100%; height: 400px"></div>
<div id="table" class="shiny-html-output"></div>
</body>
</html>