In a previous blog post I have showed
how you could use the {tidyxl} package to go from a human readable Excel Workbook to a tidy
data set (or flat file, as they are also called). Some people then contributed their solutions,
which is always something I really enjoy when it happens. This way, I also get to learn things!
@expersso proposed a solution without {tidyxl}:
Interesting data wrangling exercise in #rstats. My solution (without using {tidyxl}): https://t.co/VjuOoM82yX https://t.co/VsXFyowigu
— Eric (@expersso) September 12, 2018
Ben Stenhaug also proposed a solution on his github
which is simpler than my code in a lot of ways!
Now, it would be too bad not to further analyze this data. I’ve been wanting to play around with
the {flexdashboard} package for some time now, but never really got the opportunity to do so.
The opportunity has now arrived. Using the cleaned data from the last post, I will further tweak
it a little bit, and then produce a very simple dashboard using {flexdashboard}.
If you want to skip the rest of the blog post and go directly to the dashboard, just click here.
To make the data useful, I need to convert the strings that represent the amount of time spent
doing a task (for example “1:23”) to minutes. For this I use the {chron} package:
clean_data %
mutate(time_in_minutes = paste0(time, &quot;:00&quot;)) %__% # I need to add &quot;:00&quot; for the seconds else it won't work
mutate(time_in_minutes = chron::hours(chron::times(time_in_minutes)) * 60 + chron::minutes(chron::times(time_in_minutes)))
rio::export(clean_data, &quot;clean_data.csv&quot;)
Now we’re ready to go! Below is the code to build the dashboard; if you want to try, you should
copy and paste the code inside a Rmd document:
---
title: &quot;Time Use Survey of Luxembourguish residents&quot;
output: flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
runtime: shiny
---
`` `{r setup, include=FALSE}
library(flexdashboard)
library(shiny)
library(tidyverse)
library(plotly)
library(ggthemes)
main_categories %
rename(Activities = activities)
`` `
Inputs {.sidebar}
-----------------------------------------------------------------------
`` `{r}
selectInput(inputId = &quot;activitiesName&quot;, label = &quot;Choose an activity&quot;, choices = unique(df$Activities))
selectInput(inputId = &quot;dayName&quot;, label = &quot;Choose a day&quot;, choices = unique(df$day), selected = &quot;Year 2014_Monday til Friday&quot;)
selectInput(inputId = &quot;populationName&quot;, label = &quot;Choose a population&quot;, choices = unique(df$Population), multiple = TRUE, selected = c(&quot;Male&quot;, &quot;Female&quot;))
`` `
The Time Use Survey (TUS) aims to measure accurately how people allocate their time across different day-to-day activities. To this end, people are asked to keep records of all their activities in a time diary. For each activity, additional information is collected about whether or not the person was alone doing it or together with other persons, where did the activity take place, etc. The main studies on time use have been conducted to calculate indicators making possible comparative analysis of quality of life within the same population or between countries. International studies care more about specific activities such as work (unpaid or not), free time, leisure, personal care (including sleep), etc.
Source: http://statistiques.public.lu/en/surveys/espace-households/time-use/index.html
Layout based on https://jjallaire.shinyapps.io/shiny-biclust/
Row
-----------------------------------------------------------------------
### Minutes spent per day on certain activities
`` `{r}
dfInput % filter(Activities == input$activitiesName,
Population %in% input$populationName,
day %in% input$dayName)
})
dfInput2 % filter(Activities %in% main_categories,
Population %in% input$populationName,
day %in% input$dayName)
})
renderPlotly({
df1