4.6 Rate vs count
Next step is to give the user the chance to plot the data relative to 10,000 People or in absolute numbers.
The new ui looks like this:
ui <- fluidPage(
fluidRow(
column(
width = 8,
selectInput(
inputId = "code",
label = "Product",
choices = prod_codes,
width = "100%"
)
),
column(
width = 2,
selectInput(inputId = "y", label = "Y axis", choices = c("rate", "count"))
)
),
fluidRow(
column(width = 4, tableOutput(outputId = "diag")),
column(width = 4, tableOutput(outputId = "body_part")),
column(width = 4, tableOutput(outputId = "location"))
),
fluidRow(
column(width = 12, plotOutput(outputId = "age_sex"))
)
)
And plot rendering changes to:
server <- function(input, output, session) {
...
output$age_sex <- renderPlot(
expr = {
if (input$y == "count") {
summary() %>%
ggplot(mapping = aes(x = age, y = n, colour = sex)) +
geom_line() +
labs(y = "Estimated number of injuries")
} else {
summary() %>%
ggplot(mapping = aes(x = age, y = rate, colour = sex)) +
geom_line(na.rm = TRUE) +
labs(y = "Injuries per 10,000 people")
}
},
res = 96
)
}