title: How do you coerce shiny select inputs to be numbers to calculate average score?
body: <p>I have a shiny app where users can select different options (&quot;&quot;, very low, low, medium, high), and I want to give users an average score based on their selections within each section as well as an overall average (with very low = 1, low = 2, etc--the blank option should be treated as NA). I know if I were doing this in a normal, non-reactive dataset, I could use dplyr's <code>case_when()</code>, but I'm not sure how to do it for each input. Though I'm open to any solution, I'd appreciate one that uses tidy functions, especially case_when().</p>
  <p>The actual survey has 30 questions, so I'd prefer not to call out each input individually if possible (they all start with a similar stem, like the below example). Last, each average should be a number (not a character string), so I can do other computations later.</p>
  <p>Appreciate any help! Below is a reproducible example to demonstrate:</p>
  <pre><code>library(shiny)
  library(tidyverse)
  library(shinyjs)
  library(shinydashboard)
  library(shinyWidgets)
  
  ui &lt;- fluidPage(
      title = &quot;Personalized Quiz&quot;,
      useShinyjs(),
      useShinydashboard(),
      tabsetPanel(
          tabPanel(&quot;Quiz&quot;,
                   sidebarLayout(
                       sidebarPanel(
                           h2(&quot;Section 1&quot;),
                           selectInput(&quot;q1&quot;, &quot;Question 1&quot;,
                                       choices = c(&quot;&quot;, &quot;Very Low&quot;, &quot;Low&quot;,
                                                   &quot;Medium&quot;, &quot;High&quot;)),
                           selectInput(&quot;q2&quot;, &quot;Question 2&quot;,
                                       choices = c(&quot;&quot;, &quot;Very Low&quot;, &quot;Low&quot;,
                                                   &quot;Medium&quot;, &quot;High&quot;)),
                           h2(&quot;Section 2&quot;),
                           selectInput(&quot;q3&quot;, &quot;Question 3&quot;,
                                       choices = c(&quot;&quot;, &quot;Very Low&quot;, &quot;Low&quot;,
                                                   &quot;Medium&quot;, &quot;High&quot;)),
                           selectInput(&quot;q4&quot;, &quot;Question 4&quot;,
                                       choices = c(&quot;&quot;, &quot;Very Low&quot;, &quot;Low&quot;,
                                                   &quot;Medium&quot;, &quot;High&quot;))
                       ),
                       mainPanel(textOutput(&quot;section1_results&quot;),
                                 textOutput(&quot;section2_results&quot;),
                                 textOutput(&quot;overall_results&quot;))
  
      ))))
  
  
  server &lt;- function(input, output) {
      
      section_1 &lt;- reactive({
                          #create section_1 average here
  
      })
      
      section_2 &lt;- reactive({
                  #create section_2 average here
  
      })
      
      overall &lt;- reactive({
          #create overall average here
      })
      
      output$section1_results &lt;- renderText(paste0(&quot;Your section 1 average is &quot;, section_1, &quot;.&quot;))
      output$section2_results &lt;- renderText(paste0(&quot;Your section 2 average is &quot;, section_2, &quot;.&quot;))
      output$overall_results &lt;- renderText(paste0(&quot;Your overall average is &quot;, overall, &quot;.&quot;))
      
  
  }
  
  # Run the application 
  shinyApp(ui = ui, server = server)
  </code></pre>