├── 1-first-app
└── app.R
├── 2-histogram
└── app.R
├── 3-play-golf
└── app.R
├── 4-iris-predictor
├── app-numeric.R
├── app-slider.R
├── model.R
├── model.rds
├── testing.csv
└── training.csv
├── 5-bmi
├── about.md
└── app.R
└── README.md
/1-first-app/app.R:
--------------------------------------------------------------------------------
1 | ####################################
2 | # Data Professor #
3 | # http://youtube.com/dataprofessor #
4 | # http://github.com/dataprofessor #
5 | ####################################
6 |
7 | # Modified from Winston Chang,
8 | # https://shiny.rstudio.com/gallery/shiny-theme-selector.html
9 |
10 | # Concepts about Reactive programming used by Shiny,
11 | # https://shiny.rstudio.com/articles/reactivity-overview.html
12 |
13 | # Load R packages
14 | library(shiny)
15 | library(shinythemes)
16 |
17 |
18 | # Define UI
19 | ui <- fluidPage(theme = shinytheme("cerulean"),
20 | navbarPage(
21 | # theme = "cerulean", # <--- To use a theme, uncomment this
22 | "My first app",
23 | tabPanel("Navbar 1",
24 | sidebarPanel(
25 | tags$h3("Input:"),
26 | textInput("txt1", "Given Name:", ""),
27 | textInput("txt2", "Surname:", ""),
28 |
29 | ), # sidebarPanel
30 | mainPanel(
31 | h1("Header 1"),
32 |
33 | h4("Output 1"),
34 | verbatimTextOutput("txtout"),
35 |
36 | ) # mainPanel
37 |
38 | ), # Navbar 1, tabPanel
39 | tabPanel("Navbar 2", "This panel is intentionally left blank"),
40 | tabPanel("Navbar 3", "This panel is intentionally left blank")
41 |
42 | ) # navbarPage
43 | ) # fluidPage
44 |
45 |
46 | # Define server function
47 | server <- function(input, output) {
48 |
49 | output$txtout <- renderText({
50 | paste( input$txt1, input$txt2, sep = " " )
51 | })
52 | } # server
53 |
54 |
55 | # Create Shiny object
56 | shinyApp(ui = ui, server = server)
57 |
--------------------------------------------------------------------------------
/2-histogram/app.R:
--------------------------------------------------------------------------------
1 | ####################################
2 | # Data Professor #
3 | # http://youtube.com/dataprofessor #
4 | # http://github.com/dataprofessor #
5 | ####################################
6 |
7 | # Modified from https://shiny.rstudio.com/tutorial/written-tutorial/lesson1/
8 |
9 | library(shiny)
10 | data(airquality)
11 |
12 | # Define UI for app that draws a histogram ----
13 | ui <- fluidPage(
14 |
15 | # App title ----
16 | titlePanel("Ozone level!"),
17 |
18 | # Sidebar layout with input and output definitions ----
19 | sidebarLayout(
20 |
21 | # Sidebar panel for inputs ----
22 | sidebarPanel(
23 |
24 | # Input: Slider for the number of bins ----
25 | sliderInput(inputId = "bins",
26 | label = "Number of bins:",
27 | min = 1,
28 | max = 50,
29 | value = 30)
30 |
31 | ),
32 |
33 | # Main panel for displaying outputs ----
34 | mainPanel(
35 |
36 | # Output: Histogram ----
37 | plotOutput(outputId = "distPlot")
38 |
39 | )
40 | )
41 | )
42 |
43 | # Define server logic required to draw a histogram ----
44 | server <- function(input, output) {
45 |
46 |
47 | output$distPlot <- renderPlot({
48 |
49 | x <- airquality$Ozone
50 | x <- na.omit(x)
51 | bins <- seq(min(x), max(x), length.out = input$bins + 1)
52 |
53 | hist(x, breaks = bins, col = "#75AADB", border = "black",
54 | xlab = "Ozone level",
55 | main = "Histogram of Ozone level")
56 |
57 | })
58 |
59 | }
60 |
61 | # Create Shiny app ----
62 | shinyApp(ui = ui, server = server)
63 |
--------------------------------------------------------------------------------
/3-play-golf/app.R:
--------------------------------------------------------------------------------
1 | ####################################
2 | # Data Professor #
3 | # http://youtube.com/dataprofessor #
4 | # http://github.com/dataprofessor #
5 | ####################################
6 |
7 |
8 | # Import libraries
9 | library(shiny)
10 | library(shinythemes)
11 | library(data.table)
12 | library(RCurl)
13 | library(randomForest)
14 |
15 | # Read data
16 | weather <- read.csv(text = getURL("https://raw.githubusercontent.com/dataprofessor/data/master/weather-weka.csv") )
17 |
18 | # Build model
19 | model <- randomForest(play ~ ., data = weather, ntree = 500, mtry = 4, importance = TRUE)
20 |
21 | # Save model to RDS file
22 | # saveRDS(model, "model.rds")
23 |
24 | # Read in the RF model
25 | #model <- readRDS("model.rds")
26 |
27 | ####################################
28 | # User interface #
29 | ####################################
30 |
31 | ui <- fluidPage(theme = shinytheme("united"),
32 |
33 | # Page header
34 | headerPanel('Play Golf?'),
35 |
36 | # Input values
37 | sidebarPanel(
38 | HTML("
Input parameters
"),
39 |
40 | selectInput("outlook", label = "Outlook:",
41 | choices = list("Sunny" = "sunny", "Overcast" = "overcast", "Rainy" = "rainy"),
42 | selected = "Rainy"),
43 | sliderInput("temperature", "Temperature:",
44 | min = 64, max = 86,
45 | value = 70),
46 | sliderInput("humidity", "Humidity:",
47 | min = 65, max = 96,
48 | value = 90),
49 | selectInput("windy", label = "Windy:",
50 | choices = list("Yes" = "TRUE", "No" = "FALSE"),
51 | selected = "TRUE"),
52 |
53 | actionButton("submitbutton", "Submit", class = "btn btn-primary")
54 | ),
55 |
56 | mainPanel(
57 | tags$label(h3('Status/Output')), # Status/Output Text Box
58 | verbatimTextOutput('contents'),
59 | tableOutput('tabledata') # Prediction results table
60 |
61 | )
62 | )
63 |
64 | ####################################
65 | # Server #
66 | ####################################
67 |
68 | server <- function(input, output, session) {
69 |
70 | # Input Data
71 | datasetInput <- reactive({
72 |
73 | # outlook,temperature,humidity,windy,play
74 | df <- data.frame(
75 | Name = c("outlook",
76 | "temperature",
77 | "humidity",
78 | "windy"),
79 | Value = as.character(c(input$outlook,
80 | input$temperature,
81 | input$humidity,
82 | input$windy)),
83 | stringsAsFactors = FALSE)
84 |
85 | play <- "play"
86 | df <- rbind(df, play)
87 | input <- transpose(df)
88 | write.table(input,"input.csv", sep=",", quote = FALSE, row.names = FALSE, col.names = FALSE)
89 |
90 | test <- read.csv(paste("input", ".csv", sep=""), header = TRUE)
91 |
92 | test$outlook <- factor(test$outlook, levels = c("overcast", "rainy", "sunny"))
93 |
94 |
95 | Output <- data.frame(Prediction=predict(model,test), round(predict(model,test,type="prob"), 3))
96 | print(Output)
97 |
98 | })
99 |
100 | # Status/Output Text Box
101 | output$contents <- renderPrint({
102 | if (input$submitbutton>0) {
103 | isolate("Calculation complete.")
104 | } else {
105 | return("Server is ready for calculation.")
106 | }
107 | })
108 |
109 | # Prediction results table
110 | output$tabledata <- renderTable({
111 | if (input$submitbutton>0) {
112 | isolate(datasetInput())
113 | }
114 | })
115 |
116 | }
117 |
118 | ####################################
119 | # Create the shiny app #
120 | ####################################
121 | shinyApp(ui = ui, server = server)
122 |
--------------------------------------------------------------------------------
/4-iris-predictor/app-numeric.R:
--------------------------------------------------------------------------------
1 | ############################################
2 | # Data Professor #
3 | # http://youtube.com/dataprofessor #
4 | # http://github.com/dataprofessor #
5 | # http://facebook.com/dataprofessor #
6 | # https://www.instagram.com/data.professor #
7 | ############################################
8 |
9 | # Import libraries
10 | library(shiny)
11 | library(data.table)
12 | library(randomForest)
13 |
14 | # Read in the RF model
15 | model <- readRDS("model.rds")
16 |
17 |
18 | ####################################
19 | # User interface #
20 | ####################################
21 |
22 | ui <- pageWithSidebar(
23 |
24 | # Page header
25 | headerPanel('Iris Predictor'),
26 |
27 | # Input values
28 | sidebarPanel(
29 | #HTML("Input parameters
"),
30 | tags$label(h3('Input parameters')),
31 | numericInput("Sepal.Length",
32 | label = "Sepal Length",
33 | value = 5.1),
34 | numericInput("Sepal.Width",
35 | label = "Sepal Width",
36 | value = 3.6),
37 | numericInput("Petal.Length",
38 | label = "Petal Length",
39 | value = 1.4),
40 | numericInput("Petal.Width",
41 | label = "Petal Width",
42 | value = 0.2),
43 |
44 | actionButton("submitbutton", "Submit",
45 | class = "btn btn-primary")
46 | ),
47 |
48 | mainPanel(
49 | tags$label(h3('Status/Output')), # Status/Output Text Box
50 | verbatimTextOutput('contents'),
51 | tableOutput('tabledata') # Prediction results table
52 |
53 | )
54 | )
55 |
56 | ####################################
57 | # Server #
58 | ####################################
59 |
60 | server<- function(input, output, session) {
61 |
62 | # Input Data
63 | datasetInput <- reactive({
64 |
65 | df <- data.frame(
66 | Name = c("Sepal Length",
67 | "Sepal Width",
68 | "Petal Length",
69 | "Petal Width"),
70 | Value = as.character(c(input$Sepal.Length,
71 | input$Sepal.Width,
72 | input$Petal.Length,
73 | input$Petal.Width)),
74 | stringsAsFactors = FALSE)
75 |
76 | Species <- 0
77 | df <- rbind(df, Species)
78 | input <- transpose(df)
79 | write.table(input,"input.csv", sep=",", quote = FALSE, row.names = FALSE, col.names = FALSE)
80 |
81 | test <- read.csv(paste("input", ".csv", sep=""), header = TRUE)
82 |
83 | Output <- data.frame(Prediction=predict(model,test), round(predict(model,test,type="prob"), 3))
84 | print(Output)
85 |
86 | })
87 |
88 | # Status/Output Text Box
89 | output$contents <- renderPrint({
90 | if (input$submitbutton>0) {
91 | isolate("Calculation complete.")
92 | } else {
93 | return("Server is ready for calculation.")
94 | }
95 | })
96 |
97 | # Prediction results table
98 | output$tabledata <- renderTable({
99 | if (input$submitbutton>0) {
100 | isolate(datasetInput())
101 | }
102 | })
103 |
104 | }
105 |
106 | ####################################
107 | # Create the shiny app #
108 | ####################################
109 | shinyApp(ui = ui, server = server)
110 |
--------------------------------------------------------------------------------
/4-iris-predictor/app-slider.R:
--------------------------------------------------------------------------------
1 | ############################################
2 | # Data Professor #
3 | # http://youtube.com/dataprofessor #
4 | # http://github.com/dataprofessor #
5 | # http://facebook.com/dataprofessor #
6 | # https://www.instagram.com/data.professor #
7 | ############################################
8 |
9 | # Import libraries
10 | library(shiny)
11 | library(data.table)
12 | library(randomForest)
13 |
14 | # Read in the RF model
15 | model <- readRDS("model.rds")
16 |
17 | # Training set
18 | TrainSet <- read.csv("training.csv", header = TRUE)
19 | TrainSet <- TrainSet[,-1]
20 |
21 |
22 | ####################################
23 | # User interface #
24 | ####################################
25 |
26 | ui <- pageWithSidebar(
27 |
28 | # Page header
29 | headerPanel('Iris Predictor'),
30 |
31 | # Input values
32 | sidebarPanel(
33 | HTML("Input parameters"),
34 | sliderInput("Sepal.Length", label = "Sepal Length", value = 5.0,
35 | min = min(TrainSet$Sepal.Length),
36 | max = max(TrainSet$Sepal.Length)
37 | ),
38 | sliderInput("Sepal.Width", label = "Sepal Width", value = 3.6,
39 | min = min(TrainSet$Sepal.Width),
40 | max = max(TrainSet$Sepal.Width)),
41 | sliderInput("Petal.Length", label = "Petal Length", value = 1.4,
42 | min = min(TrainSet$Petal.Length),
43 | max = max(TrainSet$Petal.Length)),
44 | sliderInput("Petal.Width", label = "Petal Width", value = 0.2,
45 | min = min(TrainSet$Petal.Width),
46 | max = max(TrainSet$Petal.Width)),
47 |
48 | actionButton("submitbutton", "Submit", class = "btn btn-primary")
49 | ),
50 |
51 | mainPanel(
52 | tags$label(h3('Status/Output')), # Status/Output Text Box
53 | verbatimTextOutput('contents'),
54 | tableOutput('tabledata') # Prediction results table
55 |
56 | )
57 | )
58 |
59 | ####################################
60 | # Server #
61 | ####################################
62 |
63 | server<- function(input, output, session) {
64 |
65 | # Input Data
66 | datasetInput <- reactive({
67 |
68 | df <- data.frame(
69 | Name = c("Sepal Length",
70 | "Sepal Width",
71 | "Petal Length",
72 | "Petal Width"),
73 | Value = as.character(c(input$Sepal.Length,
74 | input$Sepal.Width,
75 | input$Petal.Length,
76 | input$Petal.Width)),
77 | stringsAsFactors = FALSE)
78 |
79 | Species <- 0
80 | df <- rbind(df, Species)
81 | input <- transpose(df)
82 | write.table(input,"input.csv", sep=",", quote = FALSE, row.names = FALSE, col.names = FALSE)
83 |
84 | test <- read.csv(paste("input", ".csv", sep=""), header = TRUE)
85 |
86 | Output <- data.frame(Prediction=predict(model,test), round(predict(model,test,type="prob"), 3))
87 | print(Output)
88 |
89 | })
90 |
91 | # Status/Output Text Box
92 | output$contents <- renderPrint({
93 | if (input$submitbutton>0) {
94 | isolate("Calculation complete.")
95 | } else {
96 | return("Server is ready for calculation.")
97 | }
98 | })
99 |
100 | # Prediction results table
101 | output$tabledata <- renderTable({
102 | if (input$submitbutton>0) {
103 | isolate(datasetInput())
104 | }
105 | })
106 |
107 | }
108 |
109 | ####################################
110 | # Create the shiny app #
111 | ####################################
112 | shinyApp(ui = ui, server = server)
--------------------------------------------------------------------------------
/4-iris-predictor/model.R:
--------------------------------------------------------------------------------
1 | ####################################
2 | # Data Professor #
3 | # http://youtube.com/dataprofessor #
4 | # http://github.com/dataprofessor #
5 | ####################################
6 |
7 | # Importing libraries
8 | library(RCurl) # for downloading the iris CSV file
9 | library(randomForest)
10 | library(caret)
11 |
12 | # Importing the Iris data set
13 | iris <- read.csv(text = getURL("https://raw.githubusercontent.com/dataprofessor/data/master/iris.csv") )
14 |
15 | # Performs stratified random split of the data set
16 | TrainingIndex <- createDataPartition(iris$Species, p=0.8, list = FALSE)
17 | TrainingSet <- iris[TrainingIndex,] # Training Set
18 | TestingSet <- iris[-TrainingIndex,] # Test Set
19 |
20 | write.csv(TrainingSet, "training.csv")
21 | write.csv(TestingSet, "testing.csv")
22 |
23 | TrainSet <- read.csv("training.csv", header = TRUE)
24 | TrainSet <- TrainSet[,-1]
25 |
26 | # Building Random forest model
27 |
28 | model <- randomForest(Species ~ ., data = TrainSet, ntree = 500, mtry = 4, importance = TRUE)
29 |
30 | # Save model to RDS file
31 | saveRDS(model, "model.rds")
32 |
--------------------------------------------------------------------------------
/4-iris-predictor/model.rds:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dataprofessor/rshiny_freecodecamp/23bf4df7f2e4f394d154d6cff0f8421b6f8cb861/4-iris-predictor/model.rds
--------------------------------------------------------------------------------
/4-iris-predictor/testing.csv:
--------------------------------------------------------------------------------
1 | "","Sepal.Length","Sepal.Width","Petal.Length","Petal.Width","Species"
2 | "5",5,3.6,1.4,0.2,"setosa"
3 | "9",4.4,2.9,1.4,0.2,"setosa"
4 | "14",4.3,3,1.1,0.1,"setosa"
5 | "19",5.7,3.8,1.7,0.3,"setosa"
6 | "22",5.1,3.7,1.5,0.4,"setosa"
7 | "26",5,3,1.6,0.2,"setosa"
8 | "29",5.2,3.4,1.4,0.2,"setosa"
9 | "37",5.5,3.5,1.3,0.2,"setosa"
10 | "41",5,3.5,1.3,0.3,"setosa"
11 | "42",4.5,2.3,1.3,0.3,"setosa"
12 | "55",6.5,2.8,4.6,1.5,"versicolor"
13 | "56",5.7,2.8,4.5,1.3,"versicolor"
14 | "61",5,2,3.5,1,"versicolor"
15 | "65",5.6,2.9,3.6,1.3,"versicolor"
16 | "66",6.7,3.1,4.4,1.4,"versicolor"
17 | "68",5.8,2.7,4.1,1,"versicolor"
18 | "73",6.3,2.5,4.9,1.5,"versicolor"
19 | "90",5.5,2.5,4,1.3,"versicolor"
20 | "92",6.1,3,4.6,1.4,"versicolor"
21 | "99",5.1,2.5,3,1.1,"versicolor"
22 | "103",7.1,3,5.9,2.1,"virginica"
23 | "111",6.5,3.2,5.1,2,"virginica"
24 | "112",6.4,2.7,5.3,1.9,"virginica"
25 | "113",6.8,3,5.5,2.1,"virginica"
26 | "120",6,2.2,5,1.5,"virginica"
27 | "133",6.4,2.8,5.6,2.2,"virginica"
28 | "134",6.3,2.8,5.1,1.5,"virginica"
29 | "136",7.7,3,6.1,2.3,"virginica"
30 | "146",6.7,3,5.2,2.3,"virginica"
31 | "147",6.3,2.5,5,1.9,"virginica"
32 |
--------------------------------------------------------------------------------
/4-iris-predictor/training.csv:
--------------------------------------------------------------------------------
1 | "","Sepal.Length","Sepal.Width","Petal.Length","Petal.Width","Species"
2 | "1",5.1,3.5,1.4,0.2,"setosa"
3 | "2",4.9,3,1.4,0.2,"setosa"
4 | "3",4.7,3.2,1.3,0.2,"setosa"
5 | "4",4.6,3.1,1.5,0.2,"setosa"
6 | "6",5.4,3.9,1.7,0.4,"setosa"
7 | "7",4.6,3.4,1.4,0.3,"setosa"
8 | "8",5,3.4,1.5,0.2,"setosa"
9 | "10",4.9,3.1,1.5,0.1,"setosa"
10 | "11",5.4,3.7,1.5,0.2,"setosa"
11 | "12",4.8,3.4,1.6,0.2,"setosa"
12 | "13",4.8,3,1.4,0.1,"setosa"
13 | "15",5.8,4,1.2,0.2,"setosa"
14 | "16",5.7,4.4,1.5,0.4,"setosa"
15 | "17",5.4,3.9,1.3,0.4,"setosa"
16 | "18",5.1,3.5,1.4,0.3,"setosa"
17 | "20",5.1,3.8,1.5,0.3,"setosa"
18 | "21",5.4,3.4,1.7,0.2,"setosa"
19 | "23",4.6,3.6,1,0.2,"setosa"
20 | "24",5.1,3.3,1.7,0.5,"setosa"
21 | "25",4.8,3.4,1.9,0.2,"setosa"
22 | "27",5,3.4,1.6,0.4,"setosa"
23 | "28",5.2,3.5,1.5,0.2,"setosa"
24 | "30",4.7,3.2,1.6,0.2,"setosa"
25 | "31",4.8,3.1,1.6,0.2,"setosa"
26 | "32",5.4,3.4,1.5,0.4,"setosa"
27 | "33",5.2,4.1,1.5,0.1,"setosa"
28 | "34",5.5,4.2,1.4,0.2,"setosa"
29 | "35",4.9,3.1,1.5,0.1,"setosa"
30 | "36",5,3.2,1.2,0.2,"setosa"
31 | "38",4.9,3.1,1.5,0.1,"setosa"
32 | "39",4.4,3,1.3,0.2,"setosa"
33 | "40",5.1,3.4,1.5,0.2,"setosa"
34 | "43",4.4,3.2,1.3,0.2,"setosa"
35 | "44",5,3.5,1.6,0.6,"setosa"
36 | "45",5.1,3.8,1.9,0.4,"setosa"
37 | "46",4.8,3,1.4,0.3,"setosa"
38 | "47",5.1,3.8,1.6,0.2,"setosa"
39 | "48",4.6,3.2,1.4,0.2,"setosa"
40 | "49",5.3,3.7,1.5,0.2,"setosa"
41 | "50",5,3.3,1.4,0.2,"setosa"
42 | "51",7,3.2,4.7,1.4,"versicolor"
43 | "52",6.4,3.2,4.5,1.5,"versicolor"
44 | "53",6.9,3.1,4.9,1.5,"versicolor"
45 | "54",5.5,2.3,4,1.3,"versicolor"
46 | "57",6.3,3.3,4.7,1.6,"versicolor"
47 | "58",4.9,2.4,3.3,1,"versicolor"
48 | "59",6.6,2.9,4.6,1.3,"versicolor"
49 | "60",5.2,2.7,3.9,1.4,"versicolor"
50 | "62",5.9,3,4.2,1.5,"versicolor"
51 | "63",6,2.2,4,1,"versicolor"
52 | "64",6.1,2.9,4.7,1.4,"versicolor"
53 | "67",5.6,3,4.5,1.5,"versicolor"
54 | "69",6.2,2.2,4.5,1.5,"versicolor"
55 | "70",5.6,2.5,3.9,1.1,"versicolor"
56 | "71",5.9,3.2,4.8,1.8,"versicolor"
57 | "72",6.1,2.8,4,1.3,"versicolor"
58 | "74",6.1,2.8,4.7,1.2,"versicolor"
59 | "75",6.4,2.9,4.3,1.3,"versicolor"
60 | "76",6.6,3,4.4,1.4,"versicolor"
61 | "77",6.8,2.8,4.8,1.4,"versicolor"
62 | "78",6.7,3,5,1.7,"versicolor"
63 | "79",6,2.9,4.5,1.5,"versicolor"
64 | "80",5.7,2.6,3.5,1,"versicolor"
65 | "81",5.5,2.4,3.8,1.1,"versicolor"
66 | "82",5.5,2.4,3.7,1,"versicolor"
67 | "83",5.8,2.7,3.9,1.2,"versicolor"
68 | "84",6,2.7,5.1,1.6,"versicolor"
69 | "85",5.4,3,4.5,1.5,"versicolor"
70 | "86",6,3.4,4.5,1.6,"versicolor"
71 | "87",6.7,3.1,4.7,1.5,"versicolor"
72 | "88",6.3,2.3,4.4,1.3,"versicolor"
73 | "89",5.6,3,4.1,1.3,"versicolor"
74 | "91",5.5,2.6,4.4,1.2,"versicolor"
75 | "93",5.8,2.6,4,1.2,"versicolor"
76 | "94",5,2.3,3.3,1,"versicolor"
77 | "95",5.6,2.7,4.2,1.3,"versicolor"
78 | "96",5.7,3,4.2,1.2,"versicolor"
79 | "97",5.7,2.9,4.2,1.3,"versicolor"
80 | "98",6.2,2.9,4.3,1.3,"versicolor"
81 | "100",5.7,2.8,4.1,1.3,"versicolor"
82 | "101",6.3,3.3,6,2.5,"virginica"
83 | "102",5.8,2.7,5.1,1.9,"virginica"
84 | "104",6.3,2.9,5.6,1.8,"virginica"
85 | "105",6.5,3,5.8,2.2,"virginica"
86 | "106",7.6,3,6.6,2.1,"virginica"
87 | "107",4.9,2.5,4.5,1.7,"virginica"
88 | "108",7.3,2.9,6.3,1.8,"virginica"
89 | "109",6.7,2.5,5.8,1.8,"virginica"
90 | "110",7.2,3.6,6.1,2.5,"virginica"
91 | "114",5.7,2.5,5,2,"virginica"
92 | "115",5.8,2.8,5.1,2.4,"virginica"
93 | "116",6.4,3.2,5.3,2.3,"virginica"
94 | "117",6.5,3,5.5,1.8,"virginica"
95 | "118",7.7,3.8,6.7,2.2,"virginica"
96 | "119",7.7,2.6,6.9,2.3,"virginica"
97 | "121",6.9,3.2,5.7,2.3,"virginica"
98 | "122",5.6,2.8,4.9,2,"virginica"
99 | "123",7.7,2.8,6.7,2,"virginica"
100 | "124",6.3,2.7,4.9,1.8,"virginica"
101 | "125",6.7,3.3,5.7,2.1,"virginica"
102 | "126",7.2,3.2,6,1.8,"virginica"
103 | "127",6.2,2.8,4.8,1.8,"virginica"
104 | "128",6.1,3,4.9,1.8,"virginica"
105 | "129",6.4,2.8,5.6,2.1,"virginica"
106 | "130",7.2,3,5.8,1.6,"virginica"
107 | "131",7.4,2.8,6.1,1.9,"virginica"
108 | "132",7.9,3.8,6.4,2,"virginica"
109 | "135",6.1,2.6,5.6,1.4,"virginica"
110 | "137",6.3,3.4,5.6,2.4,"virginica"
111 | "138",6.4,3.1,5.5,1.8,"virginica"
112 | "139",6,3,4.8,1.8,"virginica"
113 | "140",6.9,3.1,5.4,2.1,"virginica"
114 | "141",6.7,3.1,5.6,2.4,"virginica"
115 | "142",6.9,3.1,5.1,2.3,"virginica"
116 | "143",5.8,2.7,5.1,1.9,"virginica"
117 | "144",6.8,3.2,5.9,2.3,"virginica"
118 | "145",6.7,3.3,5.7,2.5,"virginica"
119 | "148",6.5,3,5.2,2,"virginica"
120 | "149",6.2,3.4,5.4,2.3,"virginica"
121 | "150",5.9,3,5.1,1.8,"virginica"
122 |
--------------------------------------------------------------------------------
/5-bmi/about.md:
--------------------------------------------------------------------------------
1 | #### What is BMI?
2 |
3 | **Body Mass Index (BMI)** is essentially a value obtained from the weight and height of a person [1].
4 |
5 | #### Calculating the BMI
6 | BMI can be computed by dividing the person's weight (kg) by their squared height (m) as follows:
7 |
8 | > BMI = kg/m^2
9 |
10 | where *kg* represents the person's weight and *m^2* the person's squared height.
11 |
12 | #### About this BMI Calculator
13 |
14 | This *BMI Calculator* is for adults 20 years and older. Further information on calculating BMI for children and teenagers is available from the CDC [2].
15 |
16 | #### References
17 | 1. Centers for Disease Control. [Body Mass Index (BMI)](https://www.cdc.gov/healthyweight/assessing/bmi/index.html), Accessed January 26, 2020.
18 | 2. Centers for Disease Control. [BMI Percentile Calculator for Child and Teen](https://www.cdc.gov/healthyweight/bmi/calculator.html), Accessed January 26, 2020.
19 |
--------------------------------------------------------------------------------
/5-bmi/app.R:
--------------------------------------------------------------------------------
1 | ############################################
2 | # Data Professor #
3 | # http://youtube.com/dataprofessor #
4 | # http://github.com/dataprofessor #
5 | # http://facebook.com/dataprofessor #
6 | # https://www.instagram.com/data.professor #
7 | ############################################
8 |
9 | library(shiny)
10 | library(shinythemes)
11 |
12 |
13 | ####################################
14 | # User Interface #
15 | ####################################
16 | ui <- fluidPage(theme = shinytheme("united"),
17 | navbarPage("BMI Calculator:",
18 |
19 | tabPanel("Home",
20 | # Input values
21 | sidebarPanel(
22 | HTML("Input parameters
"),
23 | sliderInput("height",
24 | label = "Height",
25 | value = 175,
26 | min = 40,
27 | max = 250),
28 | sliderInput("weight",
29 | label = "Weight",
30 | value = 70,
31 | min = 20,
32 | max = 100),
33 |
34 | actionButton("submitbutton",
35 | "Submit",
36 | class = "btn btn-primary")
37 | ),
38 |
39 | mainPanel(
40 | tags$label(h3('Status/Output')), # Status/Output Text Box
41 | verbatimTextOutput('contents'),
42 | tableOutput('tabledata') # Results table
43 | ) # mainPanel()
44 |
45 | ), #tabPanel(), Home
46 |
47 | tabPanel("About",
48 | titlePanel("About"),
49 | div(includeMarkdown("about.md"),
50 | align="justify")
51 | ) #tabPanel(), About
52 |
53 | ) # navbarPage()
54 | ) # fluidPage()
55 |
56 |
57 | ####################################
58 | # Server #
59 | ####################################
60 | server <- function(input, output, session) {
61 |
62 | # Input Data
63 | datasetInput <- reactive({
64 |
65 | bmi <- input$weight/( (input$height/100) * (input$height/100) )
66 | bmi <- data.frame(bmi)
67 | names(bmi) <- "BMI"
68 | print(bmi)
69 |
70 | })
71 |
72 | # Status/Output Text Box
73 | output$contents <- renderPrint({
74 | if (input$submitbutton>0) {
75 | isolate("Calculation complete.")
76 | } else {
77 | return("Server is ready for calculation.")
78 | }
79 | })
80 |
81 | # Prediction results table
82 | output$tabledata <- renderTable({
83 | if (input$submitbutton>0) {
84 | isolate(datasetInput())
85 | }
86 | })
87 |
88 | }
89 |
90 |
91 | ####################################
92 | # Create Shiny App #
93 | ####################################
94 | shinyApp(ui = ui, server = server)
95 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # rshiny_freecodecamp
--------------------------------------------------------------------------------