<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/shiny-app-for-mba-interviews/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.enelmargen.org/datascience/mba-shiny"> En El Margen - R-English</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>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 <em>R</em>.</p>
<p>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.</p>
<h2>Workflow</h2>
<p>First, you will need an excel with all the possible questions to ask. I compiled one <a target="_blank" rel="nofollow" href="http://enelmargen.org/docs/qs.xlsx">here</a>. 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.</p>
<p>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.</p>
<p>Now, on to the code.</p>
<h2>server.R</h2>
<p>Change it as you wish. There is a timer, that will indicate when time is running more the standard the interview suggests.</p>
<div>
<pre><code data-lang="r"><span>library</span><span>(</span>shiny<span>)</span>
<span>library</span><span>(</span>readxl<span>)</span>
<span>library</span><span>(</span>shinyjs<span>)</span>
<span>library</span><span>(</span>dplyr<span>)</span>
d <span>&lt;-</span> read_excel<span>(</span><span>&quot;qs.xlsx&quot;</span><span>)</span>
jsResetCode <span>&lt;-</span> <span>&quot;shinyjs.reset = function() {history.go(0)}&quot;</span>

shinyServer<span>(</span><span>function</span><span>(</span>input<span>,</span> output<span>,</span> session<span>)</span> <span>{</span>
  EventTime <span>&lt;-</span> <span>Sys.time</span><span>()</span>
  
  qqt <span>&lt;-</span> reactive<span>({</span>
    <span>if</span><span>(</span>input<span>$</span>response<span>==</span><span>&quot;To interviewer&quot;</span><span>){</span>
      d <span>&lt;-</span> d <span>%>%</span> filter<span>(</span>RESPONSE<span>==</span><span>&quot;To Interviewer&quot;</span><span>)</span>
    <span>}</span><span>else</span><span>{</span>
      d <span>&lt;-</span> d <span>%>%</span> filter<span>(</span>RESPONSE<span>==</span><span>&quot;To applicant&quot;</span><span>)</span>
    <span>}</span>
    
    qs <span>&lt;-</span> d<span>$</span>Q
    qn <span>&lt;-</span> <span>sample</span><span>(</span><span>row.names</span><span>(</span>d<span>),</span><span>1</span><span>)</span>
    qr <span>&lt;-</span> qs<span>[</span><span>as.numeric</span><span>(</span>qn<span>)]</span>
    <span>if</span><span>(</span><span>grepl</span><span>(</span>pattern <span>=</span> <span>&quot;(\\[SCHOOL\\])&quot;</span><span>,</span> x <span>=</span> <span>qr</span><span>)){</span>
      qr <span>&lt;-</span> <span>gsub</span><span>(</span>pattern <span>=</span> <span>&quot;(\\[SCHOOL\\])&quot;</span><span>,</span> replacement <span>=</span> input<span>$</span>school<span>,</span> x <span>=</span> <span>qr</span><span>)</span>
    <span>}</span>
    <span>as.character</span><span>(</span><span>paste0</span><span>(</span><span>&quot;Q&quot;</span><span>,</span>qn<span>,</span><span>&quot;: &quot;</span><span>,</span><span>qr</span><span>))</span>
  <span>})</span>
  
  output<span>$</span>qqt2 <span>&lt;-</span> renderText<span>({</span> 
    txt <span>&lt;-</span> qqt<span>()</span>
    txt 
    <span>})</span>
 
  output<span>$</span>eventTimeRemaining <span>&lt;-</span> renderUI<span>({</span>
    invalidateLater<span>(</span><span>1000</span><span>,</span> session<span>)</span>
    tm <span>&lt;-</span> <span>as.numeric</span><span>(</span><span>round</span><span>(</span><span>difftime</span><span>(</span>
      <span>Sys.time</span><span>(),</span> EventTime<span>,</span> units <span>=</span> <span>'secs'</span><span>)))</span>
    
    <span>if</span><span>(</span>tm<span>&lt;</span>input<span>$</span>NormalTime<span>*</span><span>60</span><span>){</span>
    HTML<span>(</span><span>paste0</span><span>(</span><span>&quot;Elapsed time: &quot;</span><span>,</span> <span>ifelse</span><span>(</span>tm<span>&lt;</span><span>60</span><span>,</span> <span>paste0</span><span>(</span>tm<span>,</span> <span>&quot; seconds.&quot;</span><span>),</span> 
                                    <span>paste0</span><span>(</span>tm<span>%/%</span><span>60</span><span>,</span> <span>&quot;:&quot;</span><span>,</span> tm<span>%%</span><span>60</span><span>,</span> <span>&quot; mins.&quot;</span><span>))))</span>
    <span>}</span><span>else</span><span>{</span>
      HTML<span>(</span><span>paste0</span><span>(</span><span>'&lt;p style=&quot;color:#9f1317;&quot;>&lt;strong>'</span><span>,</span><span>paste0</span><span>(</span><span>&quot;Time-up!! (&quot;</span><span>,</span> <span>ifelse</span><span>(</span>tm<span>&lt;</span><span>60</span><span>,</span> <span>paste0</span><span>(</span>tm<span>,</span> <span>&quot; seconds).&quot;</span><span>),</span> 
                                      <span>paste0</span><span>(</span>tm<span>%/%</span><span>60</span><span>,</span> <span>&quot;:&quot;</span><span>,</span> tm<span>%%</span><span>60</span><span>,</span> <span>&quot; mins).&quot;</span><span>)))),</span><span>'&lt;/strong>&lt;/p>'</span><span>)</span>
    <span>}</span>
  <span>})</span>
  
  observeEvent<span>(</span>input<span>$</span>reset<span>,</span> <span>{</span>
    shinyjs<span>::</span>reset<span>(</span><span>&quot;qqt&quot;</span><span>)</span>
  <span>})</span>
  
  observeEvent<span>(</span>input<span>$</span>reset_button<span>,</span> <span>{</span>js<span>$</span>reset<span>()})</span>  
  
  observeEvent<span>(</span>input<span>$</span>submit<span>,</span> <span>{</span>
    tm <span>&lt;-</span> <span>as.numeric</span><span>(</span><span>round</span><span>(</span><span>difftime</span><span>(</span>
      <span>Sys.time</span><span>(),</span> EventTime<span>,</span> units <span>=</span> <span>'secs'</span><span>)))</span>
    
    nq <span>&lt;-</span> <span>substr</span><span>(</span><span>as.character</span><span>(</span>qqt<span>()),</span> start <span>=</span> <span>1</span><span>,</span> 
           stop <span>=</span> <span>gregexpr</span><span>(</span>pattern <span>=</span> <span>&quot;:&quot;</span><span>,</span> qqt<span>())[[</span><span>1</span><span>]][</span><span>1</span><span>]</span><span>-1</span><span>)</span>
    
    dtm <span>&lt;-</span> <span>data.frame</span><span>(</span><span>&quot;School&quot;</span> <span>=</span> input<span>$</span>school<span>,</span> 
                       <span>&quot;Seconds&quot;</span> <span>=</span> tm<span>,</span>
                       <span>&quot;Question&quot;</span> <span>=</span> qqt<span>(),</span>
                       <span>&quot;Number&quot;</span> <span>=</span> nq<span>,</span>
                       <span>&quot;Fluid&quot;</span> <span>=</span> input<span>$</span>score1<span>,</span> 
                       <span>&quot;Content&quot;</span> <span>=</span> input<span>$</span>score2<span>,</span>
                      <span>&quot;Hour&quot;</span> <span>=</span> <span>Sys.time</span><span>(),</span>
                      <span>&quot;Date&quot;</span> <span>=</span> <span>Sys.Date</span><span>(),</span>
                      <span>&quot;Type&quot;</span> <span>=</span> <span>&quot;New&quot;</span><span>)</span>
    
    nm <span>&lt;-</span> <span>paste0</span><span>(</span><span>Sys.Date</span><span>(),</span>
                 <span>gsub</span><span>(</span>pattern <span>=</span> <span>&quot;:&quot;</span><span>,</span>
                      replacement <span>=</span> <span>&quot;_&quot;</span><span>,</span>
                      x <span>=</span> <span>substr</span><span>(</span><span>Sys.time</span><span>(),</span><span>12</span><span>,</span><span>19</span><span>)))</span>
    
    write.table<span>(</span>dtm<span>,</span> file <span>=</span> <span>paste0</span><span>(</span><span>&quot;Interviews_&quot;</span><span>,</span> nm<span>,</span> <span>&quot;.txt&quot;</span><span>),</span> 
                sep <span>=</span> <span>&quot;|&quot;</span><span>,</span> row.names <span>=</span> <span>FALSE</span><span>)</span>
  <span>})</span>
  
<span>})</span></code></pre>
</div>
<h2>ui.R</h2>
<div>
<pre><code data-lang="r"><span>library</span><span>(</span>shiny<span>)</span>
<span>library</span><span>(</span>shinyjs<span>)</span>
jsResetCode <span>&lt;-</span> <span>&quot;shinyjs.reset = function() {history.go(0)}&quot;</span>

shinyUI<span>(</span>fluidPage<span>(</span>
  useShinyjs<span>(),</span>
  <span># Application title</span>
  titlePanel<span>(</span><span>&quot;MBA Interview Questions&quot;</span><span>),</span>

  <span># Sidebar with a slider input for number of bins</span>
  sidebarLayout<span>(</span>
    sidebarPanel<span>(</span>
      sliderInput<span>(</span><span>&quot;NormalTime&quot;</span><span>,</span> <span>&quot;Minutes per response:&quot;</span><span>,</span>
                  min <span>=</span> <span>0</span><span>,</span> max <span>=</span> <span>60</span><span>,</span> value <span>=</span> <span>2</span>
      <span>),</span>
      selectInput<span>(</span><span>&quot;response&quot;</span><span>,</span> <span>&quot;Question type:&quot;</span><span>,</span>
                  <span>c</span><span>(</span><span>&quot;To applicant&quot;</span><span>,</span><span>&quot;To interviewer&quot;</span><span>)),</span>
          <span># you can select which schools here... </span>
      selectInput<span>(</span><span>&quot;school&quot;</span><span>,</span> <span>&quot;School:&quot;</span><span>,</span>
                  <span>c</span><span>(</span><span>&quot;School 1&quot;</span><span>,</span><span>&quot;School 2&quot;</span><span>)),</span>
      HTML<span>(</span><span>'&lt;h4> Typical Methods for Behavioural Questions &lt;/h4> &lt;br/></span>
<span> &lt;h4> &lt;strong> STAR: &lt;/strong>&lt;h4> &lt;br/></span>
<span> &lt;strong>S&lt;/strong>ituation: indentify the situation &lt;br/></span>
<span> &lt;strong>T&lt;/strong>ask: identify task or project &lt;br/></span>
<span> &lt;strong>A&lt;/strong>ction: describe what you did &lt;br/></span>
<span> &lt;strong>R&lt;/strong>esult: summarize the results &lt;br/></span>
<span> &lt;h4> &lt;strong> CAR: &lt;/strong>&lt;h4> &lt;/ br></span>
<span> &lt;strong>C&lt;/strong>ontext: describe the context &lt;br/></span>
<span> &lt;strong>A&lt;/strong>ction: describe what you did &lt;br/></span>
<span> &lt;strong>R&lt;/strong>esult: summarize the results &lt;br/></span>
<span> '</span><span>)</span>
    <span>),</span>
    mainPanel<span>(</span>
      HTML<span>(</span><span>'&lt;h1> Question &lt;/h1>'</span><span>),</span>
      hr<span>(),</span>
      h2<span>(</span>textOutput<span>(</span><span>'qqt2'</span><span>)),</span>
      uiOutput<span>(</span><span>'eventTimeRemaining'</span><span>),</span>
      hr<span>(),</span>
      sliderInput<span>(</span><span>&quot;score1&quot;</span><span>,</span> <span>&quot;Fluidity and Security:&quot;</span><span>,</span>
                  min <span>=</span> <span>0</span><span>,</span> max <span>=</span> <span>10</span><span>,</span> value <span>=</span> <span>5</span>
      <span>),</span>
      sliderInput<span>(</span><span>&quot;score2&quot;</span><span>,</span> <span>&quot;Content:&quot;</span><span>,</span>
                  min <span>=</span> <span>0</span><span>,</span> max <span>=</span> <span>10</span><span>,</span> value <span>=</span> <span>5</span>
      <span>),</span>
      extendShinyjs<span>(</span>text <span>=</span> jsResetCode<span>),</span>
      actionButton<span>(</span><span>&quot;reset_button&quot;</span><span>,</span> <span>&quot;New Question&quot;</span><span>),</span>
      actionButton<span>(</span><span>&quot;submit&quot;</span><span>,</span> <span>&quot;Score&quot;</span><span>)</span>
    <span>)</span>
  <span>)</span>
<span>))</span></code></pre>
</div>
<h2>Import to analyze</h2>
<p>This is the code used to import all of the files starting with “Interviews” from the folder.</p>
<div>
<pre><code data-lang="r">LoadManyTxt <span>&lt;-</span> <span>function</span><span>(</span>regex<span>,</span> separator <span>=</span> <span>&quot;|&quot;</span><span>){</span>
  a <span>&lt;-</span> <span>list.files</span><span>()[</span><span>grepl</span><span>(</span>pattern <span>=</span> regex<span>,</span>
                          <span>list.files</span><span>())]</span>
  datos <span>&lt;-</span> <span>NULL</span>
  <span>#import</span>
  <span>for</span><span>(</span>i <span>in</span> <span>1</span><span>:</span><span>length</span><span>(</span>a<span>)){</span>
    temp <span>&lt;-</span> <span>as.data.frame</span><span>(</span>read.delim<span>(</span>
      a<span>[</span>i<span>],</span> sep <span>=</span> separator<span>,</span>
      stringsAsFactors <span>=</span> <span>FALSE</span><span>))</span>
    
    <span>print</span><span>(</span><span>paste0</span><span>(</span><span>&quot;Importing... &quot;</span><span>,</span> a<span>[</span>i<span>]))</span>
    <span>if</span><span>(</span><span>length</span><span>(</span>temp<span>)</span><span>==</span><span>6</span><span>){</span>
      temp<span>$</span>Hora <span>&lt;-</span> <span>NA</span>
      temp<span>$</span>Fecha <span>&lt;-</span> <span>NA</span>
      temp<span>$</span>Tipo <span>&lt;-</span> <span>&quot;Previous&quot;</span>
    <span>}</span>
    datos <span>&lt;-</span> <span>rbind.data.frame</span><span>(</span>datos<span>,</span> temp<span>)</span>
    <span>print</span><span>(</span><span>paste</span><span>(</span><span>&quot;Data: &quot;</span><span>,</span> <span>length</span><span>(</span>datos<span>[,</span><span>1</span><span>]),</span><span>&quot; rows&quot;</span><span>))</span>
  <span>}</span>
  <span>return</span><span>(</span>datos<span>)</span>
<span>}</span>
<span># when in the folder, just do...</span>
d <span>&lt;-</span> LoadManyTxt<span>(</span><span>&quot;Interviews_&quot;</span><span>)</span></code></pre>
</div>
<p>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!</p>
<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://www.enelmargen.org/datascience/mba-shiny"> En El Margen - R-English</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/d0gcWSRsn0g"></a></div>