I have two picker input selectors, each has 4 labels (low, medium, large, very large) attached to a value (1,2,3,4). Once the user has made his/her selection I want to display the overall average. For some reason, my code is calculating the average input without trouble, but it doesn't consider the second selector at all. Am I missing a parenthesis somewhere?
Ideally I'd like to show the corresponding label name for the average but that's secondary. Here is a reproducible example. Many thanks in advance!
'''
if (interactive()) {
library(shiny)
library(shinyWidgets)
ui <- fluidPage(
pickerInput(
inputId = "groups_2",
label = "Select two from each group below:",
choices = c("Low" = "1", "Medium" = "2","Large" = "3", "Very Large" = "4"),
multiple = TRUE,
options = list("max-options-group" = 2)
),
verbatimTextOutput(outputId = "res_grp_2"),
pickerInput(
inputId = "classic",
label = "Select max two option below:",
choices = c("Low" = "1", "Medium" = "2","Large" = "3", "Very Large" = "4"),
multiple = TRUE,
options = list(
"max-options" = 2,
"max-options-text" = "No more!"
)
),
verbatimTextOutput(outputId = "res_classic"),
textOutput(outputId = "avg")
)
server <- function(input, output) {
output$res_grp_2 <- renderPrint(input$groups_2)
output$res_classic <- renderPrint(input$classic)
avg<-reactive(mean(as.numeric(input$groups_2, input$classic)))
output$avg<-renderText(avg())
}
shinyApp(ui, server)
}
'''