Skip to content

Instantly share code, notes, and snippets.

@primaryobjects
Created February 2, 2016 22:26
Show Gist options
  • Save primaryobjects/3e6433a96414c80ec876 to your computer and use it in GitHub Desktop.
Save primaryobjects/3e6433a96414c80ec876 to your computer and use it in GitHub Desktop.
Diabetes risk calculator. First shiny app made in R.
## Including the required R packages.
packages <- c('shiny')
if (length(setdiff(packages, rownames(installed.packages()))) > 0) {
install.packages(setdiff(packages, rownames(installed.packages())))
}
library(shiny)
shinyServer(function(input, output) {
submit <- FALSE
output$title <- eventReactive(input$score, {
'Results of prediction'
})
output$label1 <- eventReactive(input$score, {
'You entered'
})
output$label2 <- eventReactive(input$score, {
'Diabetes prediction score'
})
output$inputValue <- eventReactive(input$score, {
paste0('<pre>', input$glucose, '</pre>')
})
output$prediction <- eventReactive(input$score, {
paste0('<pre>', risk(input$glucose) * 100, '%', '</pre>')
})
})
risk <- function(glucose) {
glucose / 200
}
## deployApp() to publish to shinyapps.io
## Including the required R packages.
packages <- c('shiny')
if (length(setdiff(packages, rownames(installed.packages()))) > 0) {
install.packages(setdiff(packages, rownames(installed.packages())))
}
library(shiny)
shinyUI(pageWithSidebar(
headerPanel('Diabetes prediction'),
sidebarPanel(
numericInput('glucose', 'Glucose mg/dl', 90, min = 50, max = 200, step = 5),
actionButton('score', 'Score')
),
mainPanel(
h1(textOutput('title')),
h4(textOutput('label1')),
htmlOutput('inputValue'),
h4(textOutput('label2')),
htmlOutput('prediction')
)
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment