SlideShare a Scribd company logo
1 of 30
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

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 projectsVincent Terrasi
 
Introduction to r
Introduction to rIntroduction to r
Introduction to rgslicraf
 
German introduction to sp framework
German   introduction to sp frameworkGerman   introduction to sp framework
German introduction to sp frameworkBob German
 
Lec005 android start_program
Lec005 android start_programLec005 android start_program
Lec005 android start_programEyad Almasri
 
Getting started with titanium
Getting started with titaniumGetting started with titanium
Getting started with titaniumNaga 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 2015Mike 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 AppsSarath C
 
Getting started with Appcelerator Titanium
Getting started with Appcelerator TitaniumGetting started with Appcelerator Titanium
Getting started with Appcelerator TitaniumTechday7
 
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
 
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 tricksArtsem 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 ServicesBrian Culver
 
TypeScript and SharePoint Framework
TypeScript and SharePoint FrameworkTypeScript and SharePoint Framework
TypeScript and SharePoint FrameworkBob German
 
Workshop presentation hands on r programming
Workshop presentation hands on r programmingWorkshop presentation hands on r programming
Workshop presentation hands on r programmingNimrita 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 HTMLOlga 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

办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一fhwihughh
 
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...Florian Roscheck
 
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...dajasot375
 
Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024
Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024
Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024thyngster
 
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...Jack DiGiovanna
 
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfKantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfSocial Samosa
 
ASML's Taxonomy Adventure by Daniel Canter
ASML's Taxonomy Adventure by Daniel CanterASML's Taxonomy Adventure by Daniel Canter
ASML's Taxonomy Adventure by Daniel Cantervoginip
 
Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024Colleen Farrelly
 
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhi
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝DelhiRS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhi
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhijennyeacort
 
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一F sss
 
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /WhatsappsBeautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsappssapnasaifi408
 
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort servicejennyeacort
 
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...soniya singh
 
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degreeyuu sss
 
How we prevented account sharing with MFA
How we prevented account sharing with MFAHow we prevented account sharing with MFA
How we prevented account sharing with MFAAndrei Kaleshka
 
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptx
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptxNLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptx
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptxBoston Institute of Analytics
 
9654467111 Call Girls In Munirka Hotel And Home Service
9654467111 Call Girls In Munirka Hotel And Home Service9654467111 Call Girls In Munirka Hotel And Home Service
9654467111 Call Girls In Munirka Hotel And Home ServiceSapana Sha
 
04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationshipsccctableauusergroup
 

Recently uploaded (20)

办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
 
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
 
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
 
Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024
Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024
Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024
 
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
 
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfKantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
 
Call Girls in Saket 99530🔝 56974 Escort Service
Call Girls in Saket 99530🔝 56974 Escort ServiceCall Girls in Saket 99530🔝 56974 Escort Service
Call Girls in Saket 99530🔝 56974 Escort Service
 
ASML's Taxonomy Adventure by Daniel Canter
ASML's Taxonomy Adventure by Daniel CanterASML's Taxonomy Adventure by Daniel Canter
ASML's Taxonomy Adventure by Daniel Canter
 
Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024
 
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhi
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝DelhiRS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhi
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhi
 
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
 
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /WhatsappsBeautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
 
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
 
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
 
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
 
How we prevented account sharing with MFA
How we prevented account sharing with MFAHow we prevented account sharing with MFA
How we prevented account sharing with MFA
 
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptx
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptxNLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptx
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptx
 
9654467111 Call Girls In Munirka Hotel And Home Service
9654467111 Call Girls In Munirka Hotel And Home Service9654467111 Call Girls In Munirka Hotel And Home Service
9654467111 Call Girls In Munirka Hotel And Home Service
 
04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships
 
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
 

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.