Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thiyangt/shiny-tutorials
Shiny tutorials
https://github.com/thiyangt/shiny-tutorials
Last synced: 20 days ago
JSON representation
Shiny tutorials
- Host: GitHub
- URL: https://github.com/thiyangt/shiny-tutorials
- Owner: thiyangt
- Created: 2017-05-12T00:39:23.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-09-01T01:33:56.000Z (over 4 years ago)
- Last Synced: 2024-10-30T04:59:00.300Z (2 months ago)
- Language: HTML
- Size: 10.2 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.html
Awesome Lists containing this project
README
code{white-space: pre;}
pre:not([class]) {
background-color: white;
}if (window.hljs) {
hljs.configure({languages: []});
hljs.initHighlightingOnLoad();
if (document.readyState && document.readyState === "complete") {
window.setTimeout(function() { hljs.initHighlighting(); }, 0);
}
}h1 {
font-size: 34px;
}
h1.title {
font-size: 38px;
}
h2 {
font-size: 30px;
}
h3 {
font-size: 24px;
}
h4 {
font-size: 18px;
}
h5 {
font-size: 16px;
}
h6 {
font-size: 12px;
}
.table th:not([align]) {
text-align: left;
}.main-container {
max-width: 940px;
margin-left: auto;
margin-right: auto;
}
code {
color: inherit;
background-color: rgba(0, 0, 0, 0.04);
}
img {
max-width:100%;
height: auto;
}
.tabbed-pane {
padding-top: 12px;
}
.html-widget {
margin-bottom: 20px;
}
button.code-folding-btn:focus {
outline: none;
}$(document).ready(function () {
window.buildTabsets("TOC");
});How to develop a shiny app?
Resources: Coursera Course - Developing Data Products
Users
- Web app for your prediction algorithm: you want to create a web site so that users can input the relevant predictors and obtain their prediction.
What is Shiny?
- Shiny is a platform for creating interactive R programs embedded into a web page.
Three components in web pogamming
html: gives a webpage structure and sectioning as well as markup instructions
css: gives the style of the web page
java scripts (js): for interactivity
Introduction to Shiny
- Step 1: Install shiny
install.packages("shiny")
library(shiny)
- How to create a shiny project?
In order to create a shiny project you need two things:
1. ui.R : For use interface, controls how it looks.
2. server.R: Controls what it does.
The two files need to be in the same directory (folder).
Example 1: Output format
- Following is a minimal example of ui.R
library(shiny)
shinyUI(pageWithSidebar(############### body ################
#----- title of my shiny app -----------
headerPanel("Data science FTWI"),
#----- display of the sidebar panel-----
sidebarPanel(
h3('Sidebar text')
),
#----- display of the main panel--------
mainPanel(
h3('Main Panel text') # h3: 3rd level html heading
)
#---------------------------------------
##########################################))
- server.R
Following server.R function is not going to do anything.
library(shiny)
shinyServer(
## Even though this function is not doing anything we need the following function to be included
function(input, output){
}
#............................
)
- runApp
In R, change to the directories with these files and type runApp()
Example 2: R function for HTML markups
Note: WHen creating a shiny app you should be careful of the the commas.
- ui.R function
library(shiny)
shinyUI(pageWithSidebar(############### body ################
#----- title of my shiny app -----------
headerPanel("Illustating markup"),
#----- display of the sidebar panel-----
sidebarPanel(
h1('Sidebar text'), # comma after every h label
h1('H1 text'),
h2('H2 text'),
h3('H3 text'),
h4('H4 text') # no comma here
),
#----- display of the main panel--------
mainPanel(
h3('Main Panel text') ,
code('some code'),
p('some ordinary text')
)
#---------------------------------------
##########################################))
- server. R
This is same as example 1
library(shiny)
shinyServer(
we need the following function to be included
function(input, output){
}
)
- Example 2: output
Example 3: Illustrating inputs
- ui.R
library(shiny)
shinyUI(pageWithSidebar(
############### body ################
#----- title of my shiny app -----------
headerPanel("Illustating inputs"),
#----- display of the sidebar panel-----
sidebarPanel(
#........................................
numericInput('id1','Numeric input, labeled id1', 0, min=0, max=10, step=1),
## You will get a dropdown list where min is 0 and max is 10, increment by 1,
## id1: is the input label name
## "Numeric input, labeled id1" is the display label
#........................................
checkboxGroupInput("id2", "Checkbox",
c("Value 1" = "1",
"Value 2" = "2",
"Value 3" = "3")),
## Here you'll get a checkbox to include inputs
## id2: label name
## Checkbox: display label
#........................................
dateInput("date", "Date:")
),
## Here you'll get a blank box to include the date
## date: label name
## Date: display label
#----- display of the main panel--------
# This main panel display the outputs we entered above
mainPanel(
h3('Illustrating outputs'),
h4('You entered'),
# "id1" is the label you've given above, then you have to put "o" infront of the label "oid1"
verbatimTextOutput("oid1"),
h4('You entered'),
verbatimTextOutput("oid2"),
h4('You entered'),
verbatimTextOutput("odate"))
#---------------------------------------
##########################################))
- server.R
library(shiny)
shinyServer(
function(input, output){
#--------------------------------
# If you enter the following codes only then it will show you the things you input
output$oid1 <- renderPrint({input$id1})
output$oid2 <- renderPrint({input$id2})
output$odate <- renderPrint({input$date})
}
#---------------------------------
)
- Example 3: output
Example 4
// add bootstrap table styles to pandoc tables
function bootstrapStylePandocTables() {
$('tr.header').parent('thead').parent('table').addClass('table table-condensed');
}
$(document).ready(function () {
bootstrapStylePandocTables();
});(function () {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
document.getElementsByTagName("head")[0].appendChild(script);
})();