-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.R
76 lines (48 loc) · 1.75 KB
/
app.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
library(shiny)
library(tidyverse)
library(scales)
# library(readr)
# Define UI for slider demo app ----
ui <- fluidPage(
# App title ----
titlePanel("Monthly Co-Pay Calculator"),
# Sidebar layout with input and output definitions ----
sidebarLayout(
# Sidebar to demonstrate various slider options ----
sidebarPanel(
# Number ===================================================
# Change the value
numericInput("inNumber", "Montly Income:",
min = 1, max = 6700, value = 2500, step = 1),
# Number ===================================================
# Change the value
numericInput("fNumber", "Children in Household:",
min = 1, max = 30, value = 1, step = 1)
),
# Main panel for displaying outputs ----
mainPanel(
# Output: Table summarizing the values entered ----
textOutput("values")
)
)
)
# Define server logic for slider examples ----
server <- function(input, output) {
fam_data <- read_csv("./fam_data.csv")
test <- reactive({
cost_vec <- pull(fam_data[,2])
col_index <- if_else(input$fNumber <= 2, 3,
if_else(input$fNumber >= 8, 8, input$fNumber + 1))
# browser()
col <- pull(fam_data[,col_index])
row_index <- sum(if_else(input$inNumber > col, TRUE, FALSE), na.rm = T) + 1
return(cost_vec[row_index])
}
)
# Show the values in an HTML table ----
output$values <- renderText({
paste0("With ", input$fNumber, " children and a monthly income of ", dollar(input$inNumber), ", your estimated monthly payment is ", dollar(test()), ".")
})
}
# Create Shiny app ----
shinyApp(ui, server)