How to build a survey based health tracker app with R Shiny

[This article was first published on Posts | SERDAR KORUR, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

It is all about being positive or negative.

May be this sentence is enough to summarise our experiences from the last couple of months. Covid-19 pandemic caught us off-guard.

Going through this topic, I created an R Shiny app, which allows users to fill in a health/behaviour survey which is then converted into a location based risk score through a data analytics module. To achieve this the app:

  • uses google firebase authentication
  • asks users permission to track location via a javascript code
  • creates a risk score around users location
  • allows users to store and review their previous data

When users from a given location submit their health data, the app can assess the number of symptomatic vs healthy people and record the daily changes in the risk score around the location.

You can access the app here: cRew symptomTracker

The app will need location information and user provided health parameters as input to calculate real-time risks. You can still test the app without providing your location. If location is not provided the app will locate you automatically in a remote place. Guess where?

The green circles on the map denotes healthy and red circle denotes the people with flu like symptoms.

The risk score is a value from 0 to 25, the maximum score you can get without any disease symptoms is 4. Thus, a value higher than 4 signals a risk. If you have all of the three symptoms in the survey like coughing, high fever and breathing difficulties and going to work then the algorithm will assess your risk score as max at 25.

To create an health tracking app we need to store user submitted data.

I used firebase R package from John Coene to set up google firebase authentication so that users can sign in the app via their gmail or twitter accounts. If you want to set up firebase authentication for your shiny app please visit the package website, it is very descriptive and easy to understand.

For data storage, I used google firebase realtime database. User specific variables created during the authentication process can be used to set up user specific folders in the firebase database. Thus, users can access and only access their own data.

If you want to know more about how this process you can look at the readme of the R package (cRew).

Using modules or packaging Shiny apps make them much more manageable when the complexity increases.

If you have not used modules or packaged your Shiny apps here are some links to get you started:

Going through some example Shiny apps which utilized Golem and modules will be very helpful:

  • You can check Coronavirus Tracker from John Coene
  • or if you want to start from something simpler this one and go through the code files in the R folder.

Future thoughts

R Shiny framework is really versatile and allows you create beautiful apps with advanced features.

Instead of location, the app can also be applied to track health status of employees in big organizations. The organization may provide access to employees and they will enter their data regulary, this might help to warn individuals working in same departments or floors if some employees started to show disease symptoms. This can help to warn individuals and prevent further spread.

The survey data also can be easily integrated into a statistical/analytics pipeline to assess the results in real-time.

Until next time!

Serdar

To leave a comment for the author, please follow the link and comment on their blog: Posts | SERDAR KORUR.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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)