Shiny App for MBA Interviews

December 20, 2016
By

(This article was first published on En El Margen - R-English, and kindly contributed to R-bloggers)

A couple of weeks ago I attended some interviews as part of my process for admission into an MBA program. While most candidates would pore over the possible questions and then try to teach them to a third party to help them with a mock interview, I decided to expedite the process by building a shiny app in R.

In the name of helping anyone out there who knows R and is applying to an MBA (I know it is probably very few people), here is the code and a simple explanation of my workflow.

Workflow

First, you will need an excel with all the possible questions to ask. I compiled one here. You place this excel in the folder with the ui.R and server.R files. When a button is pressed on the app (the “score”), the shiny app will export a very small text file into that folder. This file will be separated by pipes and have 6 columns and one row: each indicating what question and school it is and the subjective score given by the interviewer to the question.

When you want to analyze the results, you simply import each file and rbind them to have a nifty data.frame. I’ll also leave the code to do this later on.

Now, on to the code.

server.R

Change it as you wish. There is a timer, that will indicate when time is running more the standard the interview suggests.

library(shiny)
library(readxl)
library(shinyjs)
library(dplyr)
d <- read_excel("qs.xlsx")
jsResetCode <- "shinyjs.reset = function() {history.go(0)}"

shinyServer(function(input, output, session) {
  EventTime <- Sys.time()
  
  qqt <- reactive({
    if(input$response=="To interviewer"){
      d <- d %>% filter(RESPONSE=="To Interviewer")
    }else{
      d <- d %>% filter(RESPONSE=="To applicant")
    }
    
    qs <- d$Q
    qn <- sample(row.names(d),1)
    qr <- qs[as.numeric(qn)]
    if(grepl(pattern = "(\\[SCHOOL\\])", x = qr)){
      qr <- gsub(pattern = "(\\[SCHOOL\\])", replacement = input$school, x = qr)
    }
    as.character(paste0("Q",qn,": ",qr))
  })
  
  output$qqt2 <- renderText({ 
    txt <- qqt()
    txt 
    })
 
  output$eventTimeRemaining <- renderUI({
    invalidateLater(1000, session)
    tm <- as.numeric(round(difftime(
      Sys.time(), EventTime, units = 'secs')))
    
    if(tm<input$NormalTime*60){
    HTML(paste0("Elapsed time: ", ifelse(tm<60, paste0(tm, " seconds."), 
                                    paste0(tm%/%60, ":", tm%%60, " mins."))))
    }else{
      HTML(paste0('

',paste0("Time-up!! (", ifelse(tm<60, paste0(tm, " seconds)."), paste0(tm%/%60, ":", tm%%60, " mins).")))),'

'
) } }) observeEvent(input$reset, { shinyjs::reset("qqt") }) observeEvent(input$reset_button, {js$reset()}) observeEvent(input$submit, { tm <- as.numeric(round(difftime( Sys.time(), EventTime, units = 'secs'))) nq <- substr(as.character(qqt()), start = 1, stop = gregexpr(pattern = ":", qqt())[[1]][1]-1) dtm <- data.frame("School" = input$school, "Seconds" = tm, "Question" = qqt(), "Number" = nq, "Fluid" = input$score1, "Content" = input$score2, "Hour" = Sys.time(), "Date" = Sys.Date(), "Type" = "New") nm <- paste0(Sys.Date(), gsub(pattern = ":", replacement = "_", x = substr(Sys.time(),12,19))) write.table(dtm, file = paste0("Interviews_", nm, ".txt"), sep = "|", row.names = FALSE) }) })

ui.R

library(shiny)
library(shinyjs)
jsResetCode <- "shinyjs.reset = function() {history.go(0)}"

shinyUI(fluidPage(
  useShinyjs(),
  # Application title
  titlePanel("MBA Interview Questions"),

  # Sidebar with a slider input for number of bins
  sidebarLayout(
    sidebarPanel(
      sliderInput("NormalTime", "Minutes per response:",
                  min = 0, max = 60, value = 2
      ),
      selectInput("response", "Question type:",
                  c("To applicant","To interviewer")),
          # you can select which schools here...        
      selectInput("school", "School:",
                  c("School 1","School 2")),
      HTML('

Typical Methods for Behavioural Questions


STAR:


Situation: indentify the situation
Task: identify task or project
Action: describe what you did
Result: summarize the results

CAR:

Context: describe the context
Action: describe what you did
Result: summarize the results
') ), mainPanel( HTML('

Question

'
), hr(), h2(textOutput('qqt2')), uiOutput('eventTimeRemaining'), hr(), sliderInput("score1", "Fluidity and Security:", min = 0, max = 10, value = 5 ), sliderInput("score2", "Content:", min = 0, max = 10, value = 5 ), extendShinyjs(text = jsResetCode), actionButton("reset_button", "New Question"), actionButton("submit", "Score") ) ) ))

Import to analyze

This is the code used to import all of the files starting with “Interviews” from the folder.

LoadManyTxt <- function(regex, separator = "|"){
  a <- list.files()[grepl(pattern = regex,
                          list.files())]
  datos <- NULL
  #import
  for(i in 1:length(a)){
    temp <- as.data.frame(read.delim(
      a[i], sep = separator,
      stringsAsFactors = FALSE))
    
    print(paste0("Importing... ", a[i]))
    if(length(temp)==6){
      temp$Hora <- NA
      temp$Fecha <- NA
      temp$Tipo <- "Previous"
    }
    datos <- rbind.data.frame(datos, temp)
    print(paste("Data: ", length(datos[,1])," rows"))
  }
  return(datos)
}
# when in the folder, just do...
d <- LoadManyTxt("Interviews_")

It might seem intense, but this definitely saved me a few hours. As for the outcome of the interviews, I was invited to join two of my school choices, so it all worked out! Although, having gone through the experience, I think the old mantra: “be yourself” is probably better advice than using this app, so use at your own risk!

To leave a comment for the author, please follow the link and comment on their blog: En El Margen - R-English.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)