Developing data products week4 Assigment

Ruben Nuñez

04/07/2020

Instructions

This peer assessed assignment has two parts. First, you will create a Shiny application and deploy it on Rstudio’s servers. Second, you will use Slidify or Rstudio Presenter to prepare a reproducible pitch presentation about your application.

Your Shiny Application:

  1. Write a shiny application with associated supporting documentation. The documentation should be thought of as whatever a user will need to get started using your application.
  2. Deploy the application on Rstudio’s shiny server
  3. Share the application link by pasting it into the provided text box
  4. Share your server.R and ui.R code on github

The application must include the following:

  1. Some form of input (widget: textbox, radio button, checkbox, …)
  2. Some operation on the ui input in sever.R
  3. Some reactive output displayed as a result of server calculations
  4. You must also include enough documentation so that a novice user could use your application.
  5. The documentation should be at the Shiny website itself. Do not post to an external link.

Test Case

It has been used a file provided by the ENI "Estatistics National Institute of Spain regarding Employment in the last 10 years.

And the objective of the app is to help on the data analysis of its content.

library(plotly)
#setwd("R//ProgrammingAssigment9.3")
employdata<- read.csv("employment.csv")
head(employdata)
##    Gender           Age Period Total
## 1 Hombres 16 y mas anos   2019  56.3
## 2 Hombres 16 y mas anos   2018  55.7
## 3 Hombres 16 y mas anos   2017  54.6
## 4 Hombres 16 y mas anos   2016  53.3
## 5 Hombres 16 y mas anos   2015  52.1
## 6 Hombres 16 y mas anos   2014  50.3

ui.Code

shinyUI(fluidPage(

# Application title
titlePanel("Employment rates in spain"),

sidebarLayout(
    sidebarPanel(
        
        selectInput("age", label = h3("Age"), 
                    choices = list("From 16 or more years" = 1, "From 16 to 24 years" = 2, 
                                   "From 16 to 54 years" = 3, "From 55 to 64 years" = 4, 
                                   "From 16 to 64 years" = 5), 
                    selected = 1),
        
        sliderInput("years",
                    h3("Number of Years:"),
                    min = 2009,
                    max = 2019,
                    value = c(2009, 2019)),    

    ),

    # Show a plot of the generated distribution
    mainPanel(
        h3("Help text"),
        helpText("Please move the selectors to move the age group and the needed 
                 years to see the trend."),
        plotlyOutput("distPlot"),
        tableOutput('table')
    )
)

))

Server Code

shinyServer(function(input, output) {

output$distPlot <- renderPlotly({

    #Load data
    employdata<- read.csv("employmentspain.csv")
    
    # generate bins based on input$bins from ui.R
    if (input$age == 1) {
        employdata <- employdata %>% filter(Age == "16 y mas anos")
    }else if (input$age == 2){
        employdata <- employdata %>% filter(Age == "De 16 a 24 anos")
    }else if (input$age == 3){
        employdata <- employdata %>% filter(Age == "De 25 a 54 anos")
    }else if (input$age == 4){
        employdata <- employdata %>% filter(Age == "De 55 a 64 anos")
    }else if (input$age == 5){
        employdata <- employdata %>% filter(Age == "De 16 a 64 anos")
    }   

    employdata <- employdata %>% filter(between(Period, input$years[1], input$years[2]))

    fig <- plot_ly(employdata, x = ~Period, y = ~Total, color=~Gender, type = 'scatter', mode = 'lines+markers')
})

})