Today at our R-Ladies meeting, a new R user wanted to know if R could be a platform to help people pick an insurance strategy based on some basic demographic data.
We weren’t sure either, so we tried to see if we could make a simple working example of the sort of thing she envisioned.

This is what we developed. You can download the dummy data here and see the app in action here. screenshot

library(shiny)
library(readxl)
library(dplyr)
insurance <- read_xlsx("HealthStrategy.xlsx")

# Define UI for application that draws a histogram
ui <- fluidPage(

   # Application title
   titlePanel("Insurance Strategy Picker"),

   # Sidebar with a slider input for number of bins
   sidebarLayout(
      sidebarPanel(
            radioButtons("age", label = h3("Age"),
                         choices = list("<70" = 1, ">70" = 2),
                         selected = 1),

            radioButtons("gender", label = h3("Gender"),
                         choices = list("Male" = 1, "Female" = 2, "Other" = 3),
                         selected = 1),

            radioButtons("diabetes", label = h3("Diabetes"),
                         choices = list("Yes" = 1, "No" = 2),
                         selected = 1)

      ),

      # Show a plot of the generated distribution
      mainPanel(
         tableOutput("distPlot")
      )
   )
)

# Define server logic required to draw a histogram
server <- function(input, output) {

   output$distPlot <- renderTable({

         insurance %>%
               filter(Age == input$age, Gender == input$gender, Diabetes == input$diabetes) %>%
               select(Strategy)

   })
}

# Run the application
shinyApp(ui = ui, server = server)