2024-04-02

Introduction

This presentation is on my shiny App project. The App has 4 Tab Panels namely:

  • Analytics
  • About the Swiss Dataset
  • More Dataset details
  • How to use App

Server.R and Ui.R code file are posted on github at: https://github.com/terhulugh/Developing-Data-Products-Cousera-Course.git

The Analytics tab has a Side Panel (Left) with ‘Variable:’ and ‘Submit’ button and a Main Panel for viewing Results.

Shiny App Code

library(shiny)
library(shinythemes)

shinyUI(
        navbarPage("Shiny App", theme = shinytheme("cerulean"),
                   tabPanel("Analytics",
                            fluidPage(
                                    titlePanel("Fertility Prediction using Swiss Dataset",
                                               hr()
                                               ),
                                    sidebarLayout(
                                            sidebarPanel(
                                                    selectInput("variable", "Variable:",
                                                                c("Agriculture" = "Agriculture",
                                                                  "Examination" = "Examination",
                                                                  "Education" = "Education",
                                                                  "Catholic" = "Catholic",
                                                                  "Infant Mortality" = "Infant.Mortality"
                                                                )),
                                                    
                                                    submitButton("Submit")
                                            ),
                                            
                                            mainPanel(
                                                    h3(textOutput("caption")),
                                                    
                                                    tabsetPanel(type = "tabs", 
                                                                tabPanel("Regression Summary", verbatimTextOutput("fit")),
                                                                tabPanel("Regression model Plot", plotOutput("swissPlot"),
                                                                )
                                                    )
                                            )
                                    )
                            )
                   ),
                   tabPanel("About the Swiss Data Set",
                            
                            h3("Swiss Fertility and Socioeconomic Indicators (1888) Data"),
                            hr(),
                            helpText("Standardized fertility measure and socio-economic indicators for each of 47 French-speaking provinces of Switzerland at about 1888.",
                                     "The socioeconomic factors used for predicting Fertility are Agriculture, Examination, Education, Catholic and Infant Mortality"),
                            h3("Format"),
                            p("The Swiss dataset used for this project has 47 observations on 6 variables."),
                            
                            h3("Note"),
                            
                            p("Files for all 182 districts in 1888 and other years have been available at"),
                            a("https://opr.princeton.edu/archive/pefp/switz.aspx")
                   ),
                   tabPanel("More Dataset Details",
                            
                            h3("Description"),
                            hr(),
                            helpText("The data collected are for 47 French-speaking “provinces” at about 1888.",
                                     " Switzerland, in 1888, was entering a period known as the demographic transition;",
                                     " i.e., its fertility was beginning to fall from the high level typical of underdeveloped countries.."),
                            h3("Format"),
                            p("A data frame with 47 observations on 6 variables."),
                            
                            p("  [, 1]   Fertility:                     Ig, common standardized fertility measure"),
                            p("  [, 2]   Agriculture:                   % of males involved in agriculture as occupation"),
                            p("  [, 3]   Examination:                   % draftees receiving highest mark on army examination"),
                            p("  [, 4]   Education:                 % education beyond primary school for draftees."),
                            p("  [, 5]   Catholic:                  % ‘catholic’ (as opposed to ‘protestant’)"),
                            p("  [, 6]   Infant.Mortality:          live births who live less than 1 year."),
                           
                            h3("Source"),
                            
                            p("Mosteller, F. and Tukey, J. W. (1977) Data Analysis and Regression: A Second Course in Statistics. Addison-Wesley, Reading Mass, Project 16P5, pages 549-551"),
                            
                            
                            h3("References"),
                            
                            p("Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole.")
                   ),
                   tabPanel("How to use App",
                            h3("Steps"),
                            hr(),
                            p("Step 1 - Click on the Analytics tab on the blue rail at the top of the App"),
                            p("Step 2 - Click on dropdown on your left to select variable to be used in predicting Fertility"),
                            p("Step 3 - Click on the Submit button"),
                            p("Step 4 - Click on the 'Regression Summary tab' to view the summary statistics"),
                            p("Step 5 - Click on the 'Regression Model Plot tab' to view the Plot"),
                            p("Step 6 - Click on any of the About the 'Swiss Dataset tab' and 'More Dataset Details tab' for details on the Dataset"),
                            )

        )
)

Fertility Prediction using Swiss Dataset

Swiss Fertility and Socioeconomic Indicators (1888) Data


Standardized fertility measure and socio-economic indicators for each of 47 French-speaking provinces of Switzerland at about 1888. The socioeconomic factors used for predicting Fertility are Agriculture, Examination, Education, Catholic and Infant Mortality

Format

The Swiss dataset used for this project has 47 observations on 6 variables.

Note

Files for all 182 districts in 1888 and other years have been available at

https://opr.princeton.edu/archive/pefp/switz.aspx

Description


The data collected are for 47 French-speaking “provinces” at about 1888. Switzerland, in 1888, was entering a period known as the demographic transition; i.e., its fertility was beginning to fall from the high level typical of underdeveloped countries..

Format

A data frame with 47 observations on 6 variables.

[, 1] Fertility: Ig, common standardized fertility measure

[, 2] Agriculture: % of males involved in agriculture as occupation

[, 3] Examination: % draftees receiving highest mark on army examination

[, 4] Education: % education beyond primary school for draftees.

[, 5] Catholic: % ‘catholic’ (as opposed to ‘protestant’)

[, 6] Infant.Mortality: live births who live less than 1 year.

Source

Mosteller, F. and Tukey, J. W. (1977) Data Analysis and Regression: A Second Course in Statistics. Addison-Wesley, Reading Mass, Project 16P5, pages 549-551

References

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole.

Steps


Step 1 - Click on the Analytics tab on the blue rail at the top of the App

Step 2 - Click on dropdown on your left to select variable to be used in predicting Fertility

Step 3 - Click on the Submit button

Step 4 - Click on the 'Regression Summary tab' to view the summary statistics

Step 5 - Click on the 'Regression Model Plot tab' to view the Plot

Step 6 - Click on any of the About the 'Swiss Dataset tab' and 'More Dataset Details tab' for details on the Dataset

library(shiny)
library(datasets)

swissData <- swiss

shinyServer(function(input, output) {
        
        formulaText <- reactive({
                paste("Fertility ~", input$variable)
        })
        
        formulaTextPoint <- reactive({
                paste("Fertility ~", "as.integer(", input$variable, ")")
        })
        
        fit <- reactive({
                lm(as.formula(formulaTextPoint()), data=swissData)
        })
        
        output$caption <- renderText({
                formulaText()
        })
        

        output$fit <- renderPrint({
                summary(fit())
        })
        
        output$swissPlot <- renderPlot({
                with(swissData, {
                        plot(as.formula(formulaTextPoint()))
                        abline(fit(), col=2)
                })
        })
        
})

Shiny App User Interface

Fertility Prediction using Swiss Dataset

Swiss Fertility and Socioeconomic Indicators (1888) Data


Standardized fertility measure and socio-economic indicators for each of 47 French-speaking provinces of Switzerland at about 1888. The socioeconomic factors used for predicting Fertility are Agriculture, Examination, Education, Catholic and Infant Mortality

Format

The Swiss dataset used for this project has 47 observations on 6 variables.

Note

Files for all 182 districts in 1888 and other years have been available at

https://opr.princeton.edu/archive/pefp/switz.aspx

Description


The data collected are for 47 French-speaking “provinces” at about 1888. Switzerland, in 1888, was entering a period known as the demographic transition; i.e., its fertility was beginning to fall from the high level typical of underdeveloped countries..

Format

A data frame with 47 observations on 6 variables.

[, 1] Fertility: Ig, common standardized fertility measure

[, 2] Agriculture: % of males involved in agriculture as occupation

[, 3] Examination: % draftees receiving highest mark on army examination

[, 4] Education: % education beyond primary school for draftees.

[, 5] Catholic: % ‘catholic’ (as opposed to ‘protestant’)

[, 6] Infant.Mortality: live births who live less than 1 year.

Source

Mosteller, F. and Tukey, J. W. (1977) Data Analysis and Regression: A Second Course in Statistics. Addison-Wesley, Reading Mass, Project 16P5, pages 549-551

References

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole.

Steps


Step 1 - Click on the Analytics tab on the blue rail at the top of the App

Step 2 - Click on dropdown on your left to select variable to be used in predicting Fertility

Step 3 - Click on the Submit button

Step 4 - Click on the 'Regression Summary tab' to view the summary statistics

Step 5 - Click on the 'Regression Model Plot tab' to view the Plot

Step 6 - Click on any of the About the 'Swiss Dataset tab' and 'More Dataset Details tab' for details on the Dataset