Get startedGet started for free

Exploring the 2014 Mental Health in Tech Survey

1. Exploring the 2014 Mental Health in Tech Survey

In this lesson, we'll build an app that explores the 2014 Mental Health in Tech survey, plus use the shinyWidgets package to see a gallery of different inputs, including code.

2. 2014 Mental Health in Tech Survey

The 2014 Mental Health in Tech Survey was ran by Open Sourcing Mental Health, a non-profit organization that aims to start a conversation about mental health in technology careers through conference talks, workshops, and by providing data on the topic. You can take the updated version of the survey on their website. The version of the data we'll be using today is filtered for non-negative ages. The inputs for the app will be questions around mental health consequences and physical versus mental health, then use those inputs to display a histogram of the age of respondents.

3. 2014 Mental Health in Tech Survey app

The first version of the app we'll build will look like this. You may notice that the plot is blank. This is because there's no default value selected for the 2nd question, which uses a pickerInput. This isn't great practice for real-world apps, but in this case will allow us to learn how to throw a custom error message to the user to let them know they should choose at least one option for the mental versus physical health question.

4. Custom error messages

Custom error messages are a great way to nudge users into using your app correctly. For example, if we had an input where users selected an age, we could throw an error if, for some reason, a user hadn't selected one and there was no default value. Again, this isn't great coding practice, but let's say it's omitted for the sake of this exercise. To throw a custom error message, you'll have to add validate, wrapped around need, inside of the render function building your output. The need function takes two arguments: first, what do you need to be false in your app. Here, we want the age input to not be blank. The second argument should be the custom error you'd like your user to see.

5. Custom error messages

Once you've added a custom error message to the app, it should look more like this.

6. shinyWidgets

shinyWidgets is a package that provides a cool function, shinyWidgetsGallery, which will open a custom app that provides a number of example inputs you can use in your apps. The nice thing about the gallery is it includes a button you can press to show the code you can copy and paste into your app to use that specific input.

7. Let's practice!

Dive in and practice using shinyWidgets to select inputs to use, plus explore the Mental Health in Tech survey including custom error messages.