SlideShare a Scribd company logo
Build Interactive Web Applications With R
Prepared by
Aep Hidayatuloh
aephidayatuloh.mail@gmail.com
Welcome to Shiny
• Shiny is an R package that makes it easy to build interactive web
applications (apps) straight from R.
• i.e. Entry data form, analytic dashboard etc.
• The default styling of a Shiny application is clean and effective.
• Very extensible and it is easy to integrate Shiny applications with your
own web content using HTML and CSS.
• JavaScript and jQuery can also be used to further extend the scope of
Shiny applications.
Requirement
• Tools
• Latest version of R or Microsoft R Open (64-bit only)
• Latest version of RStudio and shiny package
• Browser (Mozilla Firefox, Google Chrome etc.)
• Knowledge
• R programming
• Basic web knowledges
What will be discussed?
• Basic Shiny Apps
• Basic components of Shiny Apps
• Build Interactive Shiny Apps
• Publish Apps
• Create and setting account
• Publish and access the apps
Lets Get Started!
• Install R/Microsoft R Open and RStudio
• R : https://cran.r-project.org/
• MRO : https://mran.microsoft.com/open
• RStudio : https://www.rstudio.com/products/rstudio/download/
• Install shiny package
install.packages("shiny")
Hello Shiny!
library(shiny)
runExample("01_hello")
Basic Shiny Apps
Title/Header Panel
Sidebar/Input
Panel
Main/Output Panel
You can create shiny apps with single file app.R or two files ui.R and server.R
Layout
ui.R server.R
User Interface Computation Processes
Shiny ui.R and server.R
• User Interface
Control the layout, appearance, widget for user
inputs and display the output.
Eg. the title, page layout, text input, radio
button, dropdown menu, graphics output etc.
• Server
Set of instructions that uses the input provided
by user, process them and produces the
required output which is further displayed by
ui.R
ui.R server.R
Build Our First Apps
Statistical Descriptive Apps
Create an app to display statistical
descriptive with graphics
(histogram, boxplot and scatter
plot)
We will also use colourpicker
package to create colour picker
widget for the graphs.
Use
install.packages("colourpicker")
Build App
• Create shiny apps template from RStudio
• Provide Application name
• Choose Multiple File(ui.R/server.R) for Application Type
• Select folder for created shiny apps
Basic Shiny App Code
ui.R
library(shiny)
library(colourpicker)
shinyUI(
fluidPage(
headerPanel("Statistical Descriptive"),
sidebarLayout(
sidebarPanel("Input Panel"),
mainPanel("Output Panel")
)
)
)
server.R
library(shiny)
library(colourpicker)
shinyServer(function(input, output){
})
Design the User InterfacesidebarPanel(
fileInput(inputId = "file", label = "Choose CSV/Text file:"),
checkboxInput(inputId = "header", label = "First row as header", value = TRUE),
radioButtons(inputId = "delim", label = "Delimiter", choices = list("Comma"=",", "Semicolon"=";", "Blank/space"="t")),
h3("Graphics"),
selectInput(inputId = "graphs", label = "Choose graphic:",
choices = list("Histogram"="hist", "Boxplot"="boxplot", "Scatter"="scatter")),
conditionalPanel(condition = "input.graphs=='hist'",
selectInput(inputId = "column", label = "Choose variable", choices = list("")),
sliderInput(inputId = "bins", label = "Select number of bins:", value = 5, min = 2, max = 30)
),
conditionalPanel(condition = "input.graphs=='boxplot'",
selectInput(inputId = "boxcol", label = "Choose variable", choices = list(""), multiple = TRUE)
),
conditionalPanel(condition = "input.graphs=='scatter'",
selectInput(inputId = "var1", label = "Select variable 1", choices = list("")),
selectInput(inputId = "var2", label = "Select variable 2", choices = list("")),
sliderInput(inputId = "point", label = "Select point for plot:", value = 1, min = 1, max = 20)
),
colourInput(inputId = "cols", label = "Choose colour:", value = "blue", allowTransparent = TRUE, palette = "limited")
)
Design the Output Panel
sidebarPanel(
...
#input widget code
...
),
mainPanel(
uiOutput("tableTitle"),
tableOutput("preview"),
uiOutput("graphTitle"),
plotOutput("plots")
)
Run the app by click
Create the Brain
• All processes are done in server.R.
• First, read file from fileInput() with datapath of input$file
infile <- input$file
read.delim(infile$datapath, …)
• All generated objects (vector, table, plot, text, UI etc.) based on input should be created in
reactive function (reactive(), render*(), observe() etc.).
• render*()  *Output()
ui.R server.R
tableOutput("preview") output$preview <- renderTable()
uiOutput("graphTitle") output$graphTitle <- renderUI()
plotOutput("plots") output$plots <- renderPlot()
printOutput("text") output$text <- renderPrint()
Create the Brain – Read data & Preview
# Read the input file
dataset <- reactive({
if(is.null(input$file)){return(NULL)}
infile <- input$file
read.delim(infile$datapath, header = input$header, sep = input$delim)
})
# Title for preview table
output$tableTitle <- renderUI({
if(is.null(input$file)){return(NULL)}
h3("Data preview")
})
# Preview table
output$preview <- renderTable({
if(is.null(input$file)){return(NULL)}
head(dataset())
})
Create the Brain – Update Variable Name
# Update the input variable for graphs
observe({
if(!is.null(input$file) & input$graphs=="hist"){
vars <- names(dataset())
updateSelectInput(session, inputId = "column", label = "Choose variable", choices = vars, selected = vars[1])
updateSelectInput(session, inputId = "ttestcol", label = "Choose variable(s)", choices = vars, selected = vars[1])
}
else if(!is.null(input$file) & input$graphs=="boxplot"){
vars <- names(dataset())
updateSelectInput(session, inputId = "boxcol", label = "Choose variable", choices = vars, selected = vars[1])
}
else if(!is.null(input$file) & input$graphs=="scatter"){
vars <- names(dataset())
updateSelectInput(session, inputId = "var1", label = "Select variable 1", choices = vars, selected = vars[1])
updateSelectInput(session, inputId = "var2", label = "Select variable 2", choices = vars, selected = vars[2])
}
})
Create the Brain – Create Graphics
output$graphTitle <- renderUI({
if(is.null(input$file)){return(NULL)}
h3("Graphics")
})
output$plots <- renderPlot({
if(is.null(input$file)){return(NULL)}
x <- dataset()
if(input$graphs=="hist"){
bins <- seq(min(x[,input$column]), max((x[,input$column])), length.out = input$bins + 1)
hist(x[,input$column], breaks = bins, col = input$cols,
main = paste("Histogram of", input$column), xlab = input$column)
}
else if(input$graphs=="boxplot"){
boxplot(x[, input$boxcol])
}
else if(input$graphs=="scatter"){
plot(x[,c(input$var1, input$var2)], pch = input$point, xlab = input$var1, ylab = input$var2, col = input$cols)
}
})
Launch The App
Deploy Shiny Apps
There are two ways to deploy the apps :
Locally  you can run the apps on your own local machine (local
server) or local area network (no need internet access).
Web  deploy your apps to the web hosting. Shinyapps.io is free!
Deploy Your Apps To Web
• If you want your Shiny app to be accessible over the web, so that
users only need a web browser and internet access.
• Shinyapps.io is a platform as a service (PaaS) for hosting Shiny web
apps.
• Before you get started with shinyapps.io, you will need the latest
version of the rsconnect R package,
install.packages("rsconnect")
and Create a shinyapps.io account.
Create shinyapps.io Account
• Go to https://www.shinyapps.io and create a new account by sign up
or log in if you already have.
Generate Token
Generate token and copy
Publish Apps
Setting Connection
Copy and Paste the copied token
Apps Name
https://aephidayatuloh.shinyapps.io/descriptive_v1
Access The Apps
Summary
• We can create interactive apps for data visualization, i.e. dashboard,
spatial maps etc, or data entry form.
• Shiny apps is very extensible – HTML, CSS, JavaScript and JQuery.
• Create Shiny Apps with UI and Server
• Publish Shiny Apps – local or web; free or paid.
References
Shiny Galleries : https://shiny.rstudio.com/gallery/
Shiny Articles : https://shiny.rstudio.com/articles/
Beleey, Chris. 2013. Web Application Development With R Using Shiny.
Packt Publishing Ltd. Birmingham.
Build web apps with R

More Related Content

Similar to Build web apps with R

shiny.pdf
shiny.pdfshiny.pdf
shiny.pdf
Ashwini Kalantri
 
R-Shiny Cheat sheet
R-Shiny Cheat sheetR-Shiny Cheat sheet
R-Shiny Cheat sheet
Dr. Volkan OBAN
 
How to automate all your SEO projects
How to automate all your SEO projectsHow to automate all your SEO projects
How to automate all your SEO projects
Vincent Terrasi
 
Introduction to r
Introduction to rIntroduction to r
Introduction to r
gslicraf
 
German introduction to sp framework
German   introduction to sp frameworkGerman   introduction to sp framework
German introduction to sp framework
Bob German
 
Intro to appcelerator
Intro to appceleratorIntro to appcelerator
Intro to appcelerator
Mohab El-Shishtawy
 
shiny_v1.pptx
shiny_v1.pptxshiny_v1.pptx
shiny_v1.pptx
DavidFranco899488
 
Lec005 android start_program
Lec005 android start_programLec005 android start_program
Lec005 android start_program
Eyad Almasri
 
Getting started with titanium
Getting started with titaniumGetting started with titanium
Getting started with titanium
Naga Harish M
 
Apache Spark™ + IBM Watson + Twitter DataPalooza SF 2015
Apache Spark™ + IBM Watson + Twitter DataPalooza SF 2015Apache Spark™ + IBM Watson + Twitter DataPalooza SF 2015
Apache Spark™ + IBM Watson + Twitter DataPalooza SF 2015
Mike Broberg
 
Fastlane - Automation and Continuous Delivery for iOS Apps
Fastlane - Automation and Continuous Delivery for iOS AppsFastlane - Automation and Continuous Delivery for iOS Apps
Fastlane - Automation and Continuous Delivery for iOS Apps
Sarath C
 
Getting started with Appcelerator Titanium
Getting started with Appcelerator TitaniumGetting started with Appcelerator Titanium
Getting started with Appcelerator Titanium
Techday7
 
Hack Like It's 2013 (The Workshop)
Hack Like It's 2013 (The Workshop)Hack Like It's 2013 (The Workshop)
Hack Like It's 2013 (The Workshop)
Itzik Kotler
 
Introduction to R software, by Leire ibaibarriaga
Introduction to R software, by Leire ibaibarriaga Introduction to R software, by Leire ibaibarriaga
Introduction to R software, by Leire ibaibarriaga
DTU - Technical University of Denmark
 
Software Engineering
Software EngineeringSoftware Engineering
Software Engineering
Tharindu Weerasinghe
 
Headless CMS. Sitecore JSS getting started, tips and tricks
Headless CMS. Sitecore JSS getting started, tips and tricksHeadless CMS. Sitecore JSS getting started, tips and tricks
Headless CMS. Sitecore JSS getting started, tips and tricks
Artsem Prashkovich
 
Real World SharePoint Framework and Azure Services
Real World SharePoint Framework and Azure ServicesReal World SharePoint Framework and Azure Services
Real World SharePoint Framework and Azure Services
Brian Culver
 
TypeScript and SharePoint Framework
TypeScript and SharePoint FrameworkTypeScript and SharePoint Framework
TypeScript and SharePoint Framework
Bob German
 
Workshop presentation hands on r programming
Workshop presentation hands on r programmingWorkshop presentation hands on r programming
Workshop presentation hands on r programming
Nimrita Koul
 
Building Shiny Application Series - Layout and HTML
Building Shiny Application Series - Layout and HTMLBuilding Shiny Application Series - Layout and HTML
Building Shiny Application Series - Layout and HTML
Olga Scrivner
 

Similar to Build web apps with R (20)

shiny.pdf
shiny.pdfshiny.pdf
shiny.pdf
 
R-Shiny Cheat sheet
R-Shiny Cheat sheetR-Shiny Cheat sheet
R-Shiny Cheat sheet
 
How to automate all your SEO projects
How to automate all your SEO projectsHow to automate all your SEO projects
How to automate all your SEO projects
 
Introduction to r
Introduction to rIntroduction to r
Introduction to r
 
German introduction to sp framework
German   introduction to sp frameworkGerman   introduction to sp framework
German introduction to sp framework
 
Intro to appcelerator
Intro to appceleratorIntro to appcelerator
Intro to appcelerator
 
shiny_v1.pptx
shiny_v1.pptxshiny_v1.pptx
shiny_v1.pptx
 
Lec005 android start_program
Lec005 android start_programLec005 android start_program
Lec005 android start_program
 
Getting started with titanium
Getting started with titaniumGetting started with titanium
Getting started with titanium
 
Apache Spark™ + IBM Watson + Twitter DataPalooza SF 2015
Apache Spark™ + IBM Watson + Twitter DataPalooza SF 2015Apache Spark™ + IBM Watson + Twitter DataPalooza SF 2015
Apache Spark™ + IBM Watson + Twitter DataPalooza SF 2015
 
Fastlane - Automation and Continuous Delivery for iOS Apps
Fastlane - Automation and Continuous Delivery for iOS AppsFastlane - Automation and Continuous Delivery for iOS Apps
Fastlane - Automation and Continuous Delivery for iOS Apps
 
Getting started with Appcelerator Titanium
Getting started with Appcelerator TitaniumGetting started with Appcelerator Titanium
Getting started with Appcelerator Titanium
 
Hack Like It's 2013 (The Workshop)
Hack Like It's 2013 (The Workshop)Hack Like It's 2013 (The Workshop)
Hack Like It's 2013 (The Workshop)
 
Introduction to R software, by Leire ibaibarriaga
Introduction to R software, by Leire ibaibarriaga Introduction to R software, by Leire ibaibarriaga
Introduction to R software, by Leire ibaibarriaga
 
Software Engineering
Software EngineeringSoftware Engineering
Software Engineering
 
Headless CMS. Sitecore JSS getting started, tips and tricks
Headless CMS. Sitecore JSS getting started, tips and tricksHeadless CMS. Sitecore JSS getting started, tips and tricks
Headless CMS. Sitecore JSS getting started, tips and tricks
 
Real World SharePoint Framework and Azure Services
Real World SharePoint Framework and Azure ServicesReal World SharePoint Framework and Azure Services
Real World SharePoint Framework and Azure Services
 
TypeScript and SharePoint Framework
TypeScript and SharePoint FrameworkTypeScript and SharePoint Framework
TypeScript and SharePoint Framework
 
Workshop presentation hands on r programming
Workshop presentation hands on r programmingWorkshop presentation hands on r programming
Workshop presentation hands on r programming
 
Building Shiny Application Series - Layout and HTML
Building Shiny Application Series - Layout and HTMLBuilding Shiny Application Series - Layout and HTML
Building Shiny Application Series - Layout and HTML
 

Recently uploaded

[VCOSA] Monthly Report - Cotton & Yarn Statistics May 2024
[VCOSA] Monthly Report - Cotton & Yarn Statistics May 2024[VCOSA] Monthly Report - Cotton & Yarn Statistics May 2024
[VCOSA] Monthly Report - Cotton & Yarn Statistics May 2024
Vietnam Cotton & Spinning Association
 
Module 1 ppt BIG DATA ANALYTICS NOTES FOR MCA
Module 1 ppt BIG DATA ANALYTICS NOTES FOR MCAModule 1 ppt BIG DATA ANALYTICS NOTES FOR MCA
Module 1 ppt BIG DATA ANALYTICS NOTES FOR MCA
yuvarajkumar334
 
Q4FY24 Investor-Presentation.pdf bank slide
Q4FY24 Investor-Presentation.pdf bank slideQ4FY24 Investor-Presentation.pdf bank slide
Q4FY24 Investor-Presentation.pdf bank slide
mukulupadhayay1
 
Data Scientist Machine Learning Profiles .pdf
Data Scientist Machine Learning  Profiles .pdfData Scientist Machine Learning  Profiles .pdf
Data Scientist Machine Learning Profiles .pdf
Vineet
 
06-20-2024-AI Camp Meetup-Unstructured Data and Vector Databases
06-20-2024-AI Camp Meetup-Unstructured Data and Vector Databases06-20-2024-AI Camp Meetup-Unstructured Data and Vector Databases
06-20-2024-AI Camp Meetup-Unstructured Data and Vector Databases
Timothy Spann
 
一比一原版爱尔兰都柏林大学毕业证(本硕)ucd学位证书如何办理
一比一原版爱尔兰都柏林大学毕业证(本硕)ucd学位证书如何办理一比一原版爱尔兰都柏林大学毕业证(本硕)ucd学位证书如何办理
一比一原版爱尔兰都柏林大学毕业证(本硕)ucd学位证书如何办理
hqfek
 
一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理
bmucuha
 
Template xxxxxxxx ssssssssssss Sertifikat.pptx
Template xxxxxxxx ssssssssssss Sertifikat.pptxTemplate xxxxxxxx ssssssssssss Sertifikat.pptx
Template xxxxxxxx ssssssssssss Sertifikat.pptx
TeukuEriSyahputra
 
PyData London 2024: Mistakes were made (Dr. Rebecca Bilbro)
PyData London 2024: Mistakes were made (Dr. Rebecca Bilbro)PyData London 2024: Mistakes were made (Dr. Rebecca Bilbro)
PyData London 2024: Mistakes were made (Dr. Rebecca Bilbro)
Rebecca Bilbro
 
一比一原版马来西亚博特拉大学毕业证(upm毕业证)如何办理
一比一原版马来西亚博特拉大学毕业证(upm毕业证)如何办理一比一原版马来西亚博特拉大学毕业证(upm毕业证)如何办理
一比一原版马来西亚博特拉大学毕业证(upm毕业证)如何办理
eudsoh
 
Namma-Kalvi-11th-Physics-Study-Material-Unit-1-EM-221086.pdf
Namma-Kalvi-11th-Physics-Study-Material-Unit-1-EM-221086.pdfNamma-Kalvi-11th-Physics-Study-Material-Unit-1-EM-221086.pdf
Namma-Kalvi-11th-Physics-Study-Material-Unit-1-EM-221086.pdf
22ad0301
 
Build applications with generative AI on Google Cloud
Build applications with generative AI on Google CloudBuild applications with generative AI on Google Cloud
Build applications with generative AI on Google Cloud
Márton Kodok
 
一比一原版英属哥伦比亚大学毕业证(UBC毕业证书)学历如何办理
一比一原版英属哥伦比亚大学毕业证(UBC毕业证书)学历如何办理一比一原版英属哥伦比亚大学毕业证(UBC毕业证书)学历如何办理
一比一原版英属哥伦比亚大学毕业证(UBC毕业证书)学历如何办理
z6osjkqvd
 
一比一原版(UofT毕业证)多伦多大学毕业证如何办理
一比一原版(UofT毕业证)多伦多大学毕业证如何办理一比一原版(UofT毕业证)多伦多大学毕业证如何办理
一比一原版(UofT毕业证)多伦多大学毕业证如何办理
exukyp
 
一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理
一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理
一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理
eoxhsaa
 
06-18-2024-Princeton Meetup-Introduction to Milvus
06-18-2024-Princeton Meetup-Introduction to Milvus06-18-2024-Princeton Meetup-Introduction to Milvus
06-18-2024-Princeton Meetup-Introduction to Milvus
Timothy Spann
 
Senior Software Profiles Backend Sample - Sheet1.pdf
Senior Software Profiles  Backend Sample - Sheet1.pdfSenior Software Profiles  Backend Sample - Sheet1.pdf
Senior Software Profiles Backend Sample - Sheet1.pdf
Vineet
 
一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理
一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理
一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理
uevausa
 
一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理
一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理
一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理
actyx
 
一比一原版(曼大毕业证书)曼尼托巴大学毕业证如何办理
一比一原版(曼大毕业证书)曼尼托巴大学毕业证如何办理一比一原版(曼大毕业证书)曼尼托巴大学毕业证如何办理
一比一原版(曼大毕业证书)曼尼托巴大学毕业证如何办理
ytypuem
 

Recently uploaded (20)

[VCOSA] Monthly Report - Cotton & Yarn Statistics May 2024
[VCOSA] Monthly Report - Cotton & Yarn Statistics May 2024[VCOSA] Monthly Report - Cotton & Yarn Statistics May 2024
[VCOSA] Monthly Report - Cotton & Yarn Statistics May 2024
 
Module 1 ppt BIG DATA ANALYTICS NOTES FOR MCA
Module 1 ppt BIG DATA ANALYTICS NOTES FOR MCAModule 1 ppt BIG DATA ANALYTICS NOTES FOR MCA
Module 1 ppt BIG DATA ANALYTICS NOTES FOR MCA
 
Q4FY24 Investor-Presentation.pdf bank slide
Q4FY24 Investor-Presentation.pdf bank slideQ4FY24 Investor-Presentation.pdf bank slide
Q4FY24 Investor-Presentation.pdf bank slide
 
Data Scientist Machine Learning Profiles .pdf
Data Scientist Machine Learning  Profiles .pdfData Scientist Machine Learning  Profiles .pdf
Data Scientist Machine Learning Profiles .pdf
 
06-20-2024-AI Camp Meetup-Unstructured Data and Vector Databases
06-20-2024-AI Camp Meetup-Unstructured Data and Vector Databases06-20-2024-AI Camp Meetup-Unstructured Data and Vector Databases
06-20-2024-AI Camp Meetup-Unstructured Data and Vector Databases
 
一比一原版爱尔兰都柏林大学毕业证(本硕)ucd学位证书如何办理
一比一原版爱尔兰都柏林大学毕业证(本硕)ucd学位证书如何办理一比一原版爱尔兰都柏林大学毕业证(本硕)ucd学位证书如何办理
一比一原版爱尔兰都柏林大学毕业证(本硕)ucd学位证书如何办理
 
一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理
 
Template xxxxxxxx ssssssssssss Sertifikat.pptx
Template xxxxxxxx ssssssssssss Sertifikat.pptxTemplate xxxxxxxx ssssssssssss Sertifikat.pptx
Template xxxxxxxx ssssssssssss Sertifikat.pptx
 
PyData London 2024: Mistakes were made (Dr. Rebecca Bilbro)
PyData London 2024: Mistakes were made (Dr. Rebecca Bilbro)PyData London 2024: Mistakes were made (Dr. Rebecca Bilbro)
PyData London 2024: Mistakes were made (Dr. Rebecca Bilbro)
 
一比一原版马来西亚博特拉大学毕业证(upm毕业证)如何办理
一比一原版马来西亚博特拉大学毕业证(upm毕业证)如何办理一比一原版马来西亚博特拉大学毕业证(upm毕业证)如何办理
一比一原版马来西亚博特拉大学毕业证(upm毕业证)如何办理
 
Namma-Kalvi-11th-Physics-Study-Material-Unit-1-EM-221086.pdf
Namma-Kalvi-11th-Physics-Study-Material-Unit-1-EM-221086.pdfNamma-Kalvi-11th-Physics-Study-Material-Unit-1-EM-221086.pdf
Namma-Kalvi-11th-Physics-Study-Material-Unit-1-EM-221086.pdf
 
Build applications with generative AI on Google Cloud
Build applications with generative AI on Google CloudBuild applications with generative AI on Google Cloud
Build applications with generative AI on Google Cloud
 
一比一原版英属哥伦比亚大学毕业证(UBC毕业证书)学历如何办理
一比一原版英属哥伦比亚大学毕业证(UBC毕业证书)学历如何办理一比一原版英属哥伦比亚大学毕业证(UBC毕业证书)学历如何办理
一比一原版英属哥伦比亚大学毕业证(UBC毕业证书)学历如何办理
 
一比一原版(UofT毕业证)多伦多大学毕业证如何办理
一比一原版(UofT毕业证)多伦多大学毕业证如何办理一比一原版(UofT毕业证)多伦多大学毕业证如何办理
一比一原版(UofT毕业证)多伦多大学毕业证如何办理
 
一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理
一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理
一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理
 
06-18-2024-Princeton Meetup-Introduction to Milvus
06-18-2024-Princeton Meetup-Introduction to Milvus06-18-2024-Princeton Meetup-Introduction to Milvus
06-18-2024-Princeton Meetup-Introduction to Milvus
 
Senior Software Profiles Backend Sample - Sheet1.pdf
Senior Software Profiles  Backend Sample - Sheet1.pdfSenior Software Profiles  Backend Sample - Sheet1.pdf
Senior Software Profiles Backend Sample - Sheet1.pdf
 
一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理
一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理
一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理
 
一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理
一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理
一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理
 
一比一原版(曼大毕业证书)曼尼托巴大学毕业证如何办理
一比一原版(曼大毕业证书)曼尼托巴大学毕业证如何办理一比一原版(曼大毕业证书)曼尼托巴大学毕业证如何办理
一比一原版(曼大毕业证书)曼尼托巴大学毕业证如何办理
 

Build web apps with R

  • 1. Build Interactive Web Applications With R Prepared by Aep Hidayatuloh aephidayatuloh.mail@gmail.com
  • 2. Welcome to Shiny • Shiny is an R package that makes it easy to build interactive web applications (apps) straight from R. • i.e. Entry data form, analytic dashboard etc. • The default styling of a Shiny application is clean and effective. • Very extensible and it is easy to integrate Shiny applications with your own web content using HTML and CSS. • JavaScript and jQuery can also be used to further extend the scope of Shiny applications.
  • 3. Requirement • Tools • Latest version of R or Microsoft R Open (64-bit only) • Latest version of RStudio and shiny package • Browser (Mozilla Firefox, Google Chrome etc.) • Knowledge • R programming • Basic web knowledges
  • 4. What will be discussed? • Basic Shiny Apps • Basic components of Shiny Apps • Build Interactive Shiny Apps • Publish Apps • Create and setting account • Publish and access the apps
  • 5. Lets Get Started! • Install R/Microsoft R Open and RStudio • R : https://cran.r-project.org/ • MRO : https://mran.microsoft.com/open • RStudio : https://www.rstudio.com/products/rstudio/download/ • Install shiny package install.packages("shiny")
  • 7. Basic Shiny Apps Title/Header Panel Sidebar/Input Panel Main/Output Panel You can create shiny apps with single file app.R or two files ui.R and server.R Layout ui.R server.R User Interface Computation Processes
  • 8. Shiny ui.R and server.R • User Interface Control the layout, appearance, widget for user inputs and display the output. Eg. the title, page layout, text input, radio button, dropdown menu, graphics output etc. • Server Set of instructions that uses the input provided by user, process them and produces the required output which is further displayed by ui.R ui.R server.R
  • 10. Statistical Descriptive Apps Create an app to display statistical descriptive with graphics (histogram, boxplot and scatter plot) We will also use colourpicker package to create colour picker widget for the graphs. Use install.packages("colourpicker")
  • 11. Build App • Create shiny apps template from RStudio • Provide Application name • Choose Multiple File(ui.R/server.R) for Application Type • Select folder for created shiny apps
  • 12. Basic Shiny App Code ui.R library(shiny) library(colourpicker) shinyUI( fluidPage( headerPanel("Statistical Descriptive"), sidebarLayout( sidebarPanel("Input Panel"), mainPanel("Output Panel") ) ) ) server.R library(shiny) library(colourpicker) shinyServer(function(input, output){ })
  • 13. Design the User InterfacesidebarPanel( fileInput(inputId = "file", label = "Choose CSV/Text file:"), checkboxInput(inputId = "header", label = "First row as header", value = TRUE), radioButtons(inputId = "delim", label = "Delimiter", choices = list("Comma"=",", "Semicolon"=";", "Blank/space"="t")), h3("Graphics"), selectInput(inputId = "graphs", label = "Choose graphic:", choices = list("Histogram"="hist", "Boxplot"="boxplot", "Scatter"="scatter")), conditionalPanel(condition = "input.graphs=='hist'", selectInput(inputId = "column", label = "Choose variable", choices = list("")), sliderInput(inputId = "bins", label = "Select number of bins:", value = 5, min = 2, max = 30) ), conditionalPanel(condition = "input.graphs=='boxplot'", selectInput(inputId = "boxcol", label = "Choose variable", choices = list(""), multiple = TRUE) ), conditionalPanel(condition = "input.graphs=='scatter'", selectInput(inputId = "var1", label = "Select variable 1", choices = list("")), selectInput(inputId = "var2", label = "Select variable 2", choices = list("")), sliderInput(inputId = "point", label = "Select point for plot:", value = 1, min = 1, max = 20) ), colourInput(inputId = "cols", label = "Choose colour:", value = "blue", allowTransparent = TRUE, palette = "limited") )
  • 14. Design the Output Panel sidebarPanel( ... #input widget code ... ), mainPanel( uiOutput("tableTitle"), tableOutput("preview"), uiOutput("graphTitle"), plotOutput("plots") ) Run the app by click
  • 15. Create the Brain • All processes are done in server.R. • First, read file from fileInput() with datapath of input$file infile <- input$file read.delim(infile$datapath, …) • All generated objects (vector, table, plot, text, UI etc.) based on input should be created in reactive function (reactive(), render*(), observe() etc.). • render*()  *Output() ui.R server.R tableOutput("preview") output$preview <- renderTable() uiOutput("graphTitle") output$graphTitle <- renderUI() plotOutput("plots") output$plots <- renderPlot() printOutput("text") output$text <- renderPrint()
  • 16. Create the Brain – Read data & Preview # Read the input file dataset <- reactive({ if(is.null(input$file)){return(NULL)} infile <- input$file read.delim(infile$datapath, header = input$header, sep = input$delim) }) # Title for preview table output$tableTitle <- renderUI({ if(is.null(input$file)){return(NULL)} h3("Data preview") }) # Preview table output$preview <- renderTable({ if(is.null(input$file)){return(NULL)} head(dataset()) })
  • 17. Create the Brain – Update Variable Name # Update the input variable for graphs observe({ if(!is.null(input$file) & input$graphs=="hist"){ vars <- names(dataset()) updateSelectInput(session, inputId = "column", label = "Choose variable", choices = vars, selected = vars[1]) updateSelectInput(session, inputId = "ttestcol", label = "Choose variable(s)", choices = vars, selected = vars[1]) } else if(!is.null(input$file) & input$graphs=="boxplot"){ vars <- names(dataset()) updateSelectInput(session, inputId = "boxcol", label = "Choose variable", choices = vars, selected = vars[1]) } else if(!is.null(input$file) & input$graphs=="scatter"){ vars <- names(dataset()) updateSelectInput(session, inputId = "var1", label = "Select variable 1", choices = vars, selected = vars[1]) updateSelectInput(session, inputId = "var2", label = "Select variable 2", choices = vars, selected = vars[2]) } })
  • 18. Create the Brain – Create Graphics output$graphTitle <- renderUI({ if(is.null(input$file)){return(NULL)} h3("Graphics") }) output$plots <- renderPlot({ if(is.null(input$file)){return(NULL)} x <- dataset() if(input$graphs=="hist"){ bins <- seq(min(x[,input$column]), max((x[,input$column])), length.out = input$bins + 1) hist(x[,input$column], breaks = bins, col = input$cols, main = paste("Histogram of", input$column), xlab = input$column) } else if(input$graphs=="boxplot"){ boxplot(x[, input$boxcol]) } else if(input$graphs=="scatter"){ plot(x[,c(input$var1, input$var2)], pch = input$point, xlab = input$var1, ylab = input$var2, col = input$cols) } })
  • 20. Deploy Shiny Apps There are two ways to deploy the apps : Locally  you can run the apps on your own local machine (local server) or local area network (no need internet access). Web  deploy your apps to the web hosting. Shinyapps.io is free!
  • 21. Deploy Your Apps To Web • If you want your Shiny app to be accessible over the web, so that users only need a web browser and internet access. • Shinyapps.io is a platform as a service (PaaS) for hosting Shiny web apps. • Before you get started with shinyapps.io, you will need the latest version of the rsconnect R package, install.packages("rsconnect") and Create a shinyapps.io account.
  • 22. Create shinyapps.io Account • Go to https://www.shinyapps.io and create a new account by sign up or log in if you already have.
  • 25. Setting Connection Copy and Paste the copied token
  • 28. Summary • We can create interactive apps for data visualization, i.e. dashboard, spatial maps etc, or data entry form. • Shiny apps is very extensible – HTML, CSS, JavaScript and JQuery. • Create Shiny Apps with UI and Server • Publish Shiny Apps – local or web; free or paid.
  • 29. References Shiny Galleries : https://shiny.rstudio.com/gallery/ Shiny Articles : https://shiny.rstudio.com/articles/ Beleey, Chris. 2013. Web Application Development With R Using Shiny. Packt Publishing Ltd. Birmingham.