Web Apps in R

Web Apps in R

Building your first application using R I Shiny Package

Table of contents

No heading

No headings in the article.

Introduction

An R package called Shiny enables us to create interactive web applications. Shiny includes packages like glossy dashboards, shiny themes, etc. We can install web applications on our server using Shinyapps.io or Digital Ocean. Examine ShinyGallery at https://shiny.rstudio.com/gallery/.

Structure of a shiny web app:

Shiny web app composed of 3 components which are:

*The front that receives user input values is called the user interface (ui . R).

*The backend, which processes these input data to create output results that are ultimately played on the website, is the server function (server. R).

Input Data ā†’UIā†’Server(Process/Analyze input data)

ShinySpp function which fuses (User interface and server components).

Output resultsā†UI ā†Server(Process/Analyze input data).

User interface:

We need to make out R script ready and use it for the User interface where we want to develop our We. Let's make a web application where we want to Create a histogram out of Ozone Levels.

Let's use my data on air quality,

library(shiny)

data(airquality)

User Interface:

Our first part is to write code for the user interface of our web development. Let's write the code,

library(shiny)

data(airquality)

#Define UI for an app that draws a histogram ----

ui <- fluidPage(

#App title ----

titlePanel("Ozone level!"),

#Sidebar layout with input and output definitions ----

sidebarLayout(

# Sidebar panel for inputs ----

sidebarPanel(

# Input: Slider for the number of bins ----

sliderInput(inputId = "bins",

label = "Number of bins:",

min = 1,

max = 50,

value = 30)

),

#Main panel for displaying outputs----

mainPanel(

#output: Histogram----

plotOutput(outputId = "disPlot")

)

)

)

Server:

As I said the server is a function that defines the behavior and logic of the app, which defines the layout and appearance of the app.

#Define server logic required to draw a histogram

server <- function(input,output) {

output$disPlot <- renderPlot({

x <- airquality$Ozone

x <- na.omit(x)

bins <- seq(min(x), max(x),length.out = input$bins + 1)

hist(x, breaks = bins, col = "#75AADB", border = "black",

xlab = "Ozone level",

main = "Histogramof Ozone level"

})

}

ShinySpp function:

#Create a shiny app---

ShinyApp(ui = ui, server = server)

Conclusion:

Here, we've covered how to use R and Shiny web development to assess the air quality and create a histogram from it.

Ā